I am writing an application using Tkinter along with threading.
The problem I got is, after closing the main app, some thread is still running, and I need a way to c
I will add my workaround for this, in case anyone came across the same issue. I was following the suggestion from here. I intercept the windows' closing event to set my flag that marks the root
is already dead, and check for that flag when I need.
exitFlag = False
def thread_method():
global root, exitFlag
if not exitFlag:
// execute the code relate to root
def on_quit():
global exitFlag
exitFlag = True
root.destroy()
root.protocol("WM_DELETE_WINDOW", on_quit)
If you are using something like this:
import Tkinter
root = Tkinter.Tk()
root.bind('<space>', lambda e: root.quit()) # quitting by pressing spacebar
root.mainloop()
and not: root.destroy()
then the quit method will kill the Tcl interpreter not just breaks out from the mainloop and deletes all widgets. So once you called root.quit()
you can be sure, that your root
is completely dead!
All the other methods you suggested (like: wminfo_exists()
) are only available when at least one valid Tk
exists.
NOTE:
If you are using more than one mainloop, you should use the destroy method to make sure, that your main mainloop won't be killed -- but I don't think this is your case.