Python method strangely on pause until tkinter root is closed Python method strangely on pause until tkinter root is closed tkinter tkinter

Python method strangely on pause until tkinter root is closed


The concept of mainloop assumes that you first create and initialize objects (well, at least these that are required at application start, i.e. not used dynamically), set event handlers (implement interface logic) and then go into infinite event handling (what User Interface essentially is), i.e. main loop. So, that is why you see it as it "hangs". This is called event-driven programming

And the important thing is that this event handling is done in one single place, like that:

class GUIApp(tk.Tk):   ...app = GUIApp()app.mainloop()

So, the mainloop returns when the window dies.


Until I have some time to refactor my code, I solved the problem by adding the following line to my destroy() calls:

self.quit() # Ends mainloopself.master.destroy() # Destroys master (window)

I understand this doesn't not solve the bad structure of my code, but it answers my specific question. destroy() doesn't end the mainloop of TopLevels, but quit() does. Adding this line makes my code execute in a predictable way.

I will be accepting @pmod 's answer as soon as I have refactored my code and verified his claim that the Tk() mainloop will cover all child TopLevels.