0

Hi all,

Just wondering if there is a way to see if a window has been destroyed or not.

eg:

root = Tk()

bla ...
bla ...

if root has been destroyed:
    do something...

thanks in advance
a1eio

2
Contributors
2
Replies
3
Views
9 Years
Discussion Span
Last Post by a1eio
1

Not very elegant, but try to do anything within a try/except?

try:
     Tkinter.Label(root).pack()
except:
     print "No window exists"

## Edit:  Modifing a well known label example
##        Uncomment the root.destroy() line
from Tkinter import *
root=Tk()

def changeLabel():
    myString.set("I'm, a-fraid we're fresh out of red Leicester, sir. ")
    ##root.destroy()
    try:
         label2=Label(root).pack()
    except:
         print "No window exists"
    
myString=StringVar()
Label(root,textvariable=myString).pack()
myString.set("Well, eh, how about a little red Leicester.")
Button(root,text='Click Me',command=changeLabel).pack()
root.mainloop()
Votes + Comments
nice idea
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.