How To Create New Tkinter Window After Mainloop()?
I want to dynamically create Tkinter windows on my screen. I understand that I should only have one mainloop(). I use the threading module to make mainloop execute in a seperate th
Solution 1:
How do I create more Tkinter windows after I executed mainloop?
You don't. That's not how Tkinter is designed to work. You should always call mainloop exactly once, and from the main thread.
Solution 2:
Additional (non-root) windows are simply Toplevel
widgets. You would simply subclass Toplevel
, and call it from within your main class:
classMyCustomWindow(tkinter.Toplevel):def__init__(self):
tkinter.Toplevel.__init__(self)
#setup goes hereclassApp(tkinter.Tk):defsomeCallback(self):
self.anotherWindow = MyCustomWindow()
EDIT
You don't have to subclass Toplevel
of course, you can use it directly.
Post a Comment for "How To Create New Tkinter Window After Mainloop()?"