Tkinter Toplevel spawned in event handler

Fredrik Lundh fredrik at pythonware.com
Sat Apr 28 06:41:45 EDT 2001


Alexander Slusarczyk wrote:

> class MyWin(Toplevel):
>     def __init__(self,master,number):
>         Toplevel.__init__(self,master)
>
>         self.number = number
>         Label( self , text=str(self.number) ).pack()
>
>         self.bind("<Escape>", self.cancel)
>
>         self.wait_window(self)

wait_window waits until the window is destroyed.

you won't get back from this function call (and thus from the
MyWin constructor) until you've destroyed the window.

> Canceled 2
> Canceled 1
> Canceled 0
>
> it seems that MyWin(root,x) for a window only returns, after the MyWin() for
> all the windows created AFTER x have returned (?!)
>
> Am I making any sense?
> Does anyone have an explanation, or - preferably - a fix ?

any reason you cannot just remove the wait_window call?

Cheers /F





More information about the Python-list mailing list