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 check whether the root windows has been destroyed to avoid the TclError: can't invoke "wm" command
.
All methods I know: wminfo_exists()
and state()
all return error once the root is destroyed.
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 love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With