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

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()
commented: nice idea +8

ah, that'll work

good idea

thanks

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.