As I mentioned in the comment lines, the idea behind is like this:
There is a root and a button on it, once the button's clicked there will be a splash screen popping up first while the elements of the top level getting ready but without the root screen getting frozen. Is there any way to make this happen? Thanks in advance!
from tkinter import *
import customtkinter
import threading
def splash_screen():
global splash_screen
splash_screen = Tk()
label = customtkinter.CTkLabel(splash_screen, text="PLEASE WAIT...")
label.pack(pady=30, padx=30)
def initiate():
# get elements of the toplevel
pass
def toplevel():
# second main window after root
pass
def func1():
# to avoid root freezing
threading.Thread(target=func2).start()
def func2():
thread = threading.Thread(target=initiate)
thread.start()
splash_screen()
# wait until toplevel is ready
thread.join()
splash_screen.destroy()
toplevel()
root = customtkinter.CTk()
button = customtkinter.CTkButton(root, command=func1)
button.pack(pady=10, padx=10)
root.mainloop()
Traceback:
Exception in Tkinter callback
Traceback (most recent call last):
File "D:\Python311\Lib\tkinter\__init__.py", line 1948, in __call__
return self.func(*args)
^^^^^^^^^^^^^^^^
File "D:\Python311\Lib\tkinter\__init__.py", line 861, in callit
func(*args)
File "D:\Python311\Lib\site-packages\customtkinter\windows\widgets\scaling\scaling_tracker.py", line 178, in check_dpi_scaling
if window.winfo_exists() and not window.state() == "iconic":
^^^^^^^^^^^^^^^^^^^^^
File "D:\Python311\Lib\tkinter\__init__.py", line 1139, in winfo_exists
self.tk.call('winfo', 'exists', self._w))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
RuntimeError: main thread is not in main loop