python Tkinter, check if root has been destroyed?

前端 未结 2 2003
情歌与酒
情歌与酒 2020-12-20 16:04

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

2条回答
  •  执笔经年
    2020-12-20 16:33

    If you are using something like this:

    import Tkinter
    
    root = Tkinter.Tk()
    root.bind('', 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.

提交回复
热议问题