Help closing seconds Tkinter window
Matthew Dixon Cowles
matt at mondoinfo.com
Mon Apr 30 22:42:27 EDT 2001
On Mon, 30 Apr 2001 17:08:24 -0500, Rob Eden <rob at netzilient.com> wrote:
> I have two windows in my application: one is the "main" winodw
>and is always present, so it's using the default window. The second
>window is only available sometimes, so I'm using a Toplevel. The
>second window can disappear for two reasons: 1) the user clicks a
>button (this part's easy) or 2) after a timeout. This does not seem
>to be easy.
Hm. It should be.
> I've tried using destroy(), but it just seems to ignore it. I've
>tried using withdraw(), but that hangs. So, being a Java programmer,
>I figured that maybe the GUI thread needs to call this method. The
>only way I could see that I thought might do this is the "after()"
>method... but that also hnags when called. Since there's no good
>documentation for that method that I've found (if it exists, please
>point me!), I'm not really sure that that's even what that method
>does.
The best documentation for Tkinter than I know of is Fredrik Lundh's
excellent An Introduction to Tkinter:
http://www.pythonware.com/library/tkinter/introduction/index.htm
after() is described at (wrapped for line length):
http://www.pythonware.com/library/tkinter/
introduction/x9129-alarm-handlers-and-other.htm
It's a little hard to tell just what the problem you're having is. If
destroy is being ignored something odd is surely up. I'll append an
example that may help. If it doesn't, can you post a minimum example
that fails?
Regards,
Matt
from Tkinter import *
class mainWin:
def __init__(self,root):
self.root=root
b=Button(self.root,text="foo",command=self.otherWin)
b.pack()
return None
def otherWin(self):
t=Toplevel()
l=Label(t,text="bar")
l.pack()
self.root.after(5000,t.destroy)
return None
def main():
root=Tk()
mainWin(root)
root.mainloop()
return None
if __name__=="__main__":
main()
More information about the Python-list
mailing list