mainloop throwing error #2234
-
I want to create a splash screen. in tkinter i can just call tkinter.mainloop() to run any added window. However ctk throws error: Traceback (most recent call last): |
Beta Was this translation helpful? Give feedback.
Replies: 18 comments 39 replies
-
Show full code please |
Beta Was this translation helpful? Give feedback.
-
|
Beta Was this translation helpful? Give feedback.
-
You forgot to put splash.mainloop() |
Beta Was this translation helpful? Give feedback.
-
That's why there was an error. |
Beta Was this translation helpful? Give feedback.
-
@BhagyaJyoti22006, did it work? |
Beta Was this translation helpful? Give feedback.
-
I am trying to have a splash screen work. therefore i put mainloop(). In tkinter, the code works with just mainloop(). splash.mainloop would only loop till splash is there. after its destroyed, no loop. |
Beta Was this translation helpful? Give feedback.
-
Try root.splash() |
Beta Was this translation helpful? Give feedback.
-
well, root is not defined at that moment. Traceback (most recent call last): If you meant root.mainloop(), that also throwing similar error. |
Beta Was this translation helpful? Give feedback.
-
Just put root.mainloop() Inside the function. |
Beta Was this translation helpful? Give feedback.
-
root code wont work before splash destroys. So, without splash.mainloop, the code just closes without any window.
|
Beta Was this translation helpful? Give feedback.
-
from customtkinter import *
from sys import *
splash = CTk()
splash.title("splash")
splash.geometry("300x200")
splash_label = CTkLabel(splash, text="splash screen text")
splash_label.place(x=4,y=8)
def run():
splash.mainloop()
def window():
splash.destroy()
root=CTk()
root.title("title")
root.geometry("500x550")
root.protocol("WM_DELETE_WINDOW", exit)
root.mainloop()
splash.after(3000, window)
run() this might be solution to your problem |
Beta Was this translation helpful? Give feedback.
-
Tried your code, still getting:
|
Beta Was this translation helpful? Give feedback.
-
It disappears, when you exit program. |
Beta Was this translation helpful? Give feedback.
-
Snimanje.2024-01-28.101134.mp4 |
Beta Was this translation helpful? Give feedback.
-
Got it mate. But can we somehow get rid of that error message? |
Beta Was this translation helpful? Give feedback.
-
this is 100% solution. When you check it, mark it as an answer: from customtkinter import *
from sys import *
splash = CTk()
splash.title("splash")
splash.geometry("300x200")
splash_label = CTkLabel(splash, text="splash screen text")
splash_label.place(x=4,y=8)
def run_app():
splash.mainloop()
def window():
splash.withdraw()
splash.quit()
root=CTk()
root.title("title")
root.geometry("500x550")
root.protocol("WM_DELETE_WINDOW", exit)
root.mainloop()
splash.after(3000, window)
run_app()
#it disappears |
Beta Was this translation helpful? Give feedback.
-
This is my new code. If that button is clicked, the dialog is closed. Few files will be modified. And dialog is reopened. |
Beta Was this translation helpful? Give feedback.
-
this might be a solution: import customtkinter as ctk
import sys
class App(ctk.CTk):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.geometry("300x300")
self.protocol("WM_DELETE_WINDOW", sys.exit)
self.button = ctk.CTkButton(self, command=self.close)
self.button.grid(row=0, column=0)
self.checkbox = ctk.CTkCheckBox(self, text="reopen", onvalue="yes", offvalue="no")
self.checkbox.grid(row=0, column=1)
def close(self):
self.checkboxvalueget = self.checkbox.get()
if self.checkboxvalueget == "yes":
self.withdraw()
self.quit()
self.newroot = ctk.CTk()
self.newroot.geometry("300x300")
self.newroot.protocol("WM_DELETE_WINDOW", sys.exit)
self.newroot.mainloop()
else:
sys.exit()
def main():
root = App()
root.mainloop()
if __name__ == "__main__":
main() |
Beta Was this translation helpful? Give feedback.
this is 100% solution. When you check it, mark it as an answer: