[Tkinter-discuss] Returning control from a toplevel window

Michael Lange klappnase at web.de
Wed Apr 28 09:59:35 CEST 2010


Hi,

On Tue, 27 Apr 2010 15:44:39 -0700
Guido Carballo-Guerrero <charras at me.com> wrote:

> How can I get back into a while loop if I go to a new pop-up toplevel
> window, that is created when I press one button.
> 
> I'm attaching a sample of the code that I'm trying to make. The
> problem that I have is that after the button is press and the new
> toplevel window, what ever is inside of the while loop doesn't do
> anything anymore. Is as if I got out of the while loop.
> 
> Is there a way in which I can get back into the while loop once the
> toplevel window is destroy?
> 
> Guido
> 
(...)
> def new():
>     root2 = Tkt.Toplevel()
> 
>     def ask_quit2():
>         root2.destroy()
>             
>     root2.protocol("WM_DELETE_WINDOW", ask_quit2)
> 
>     L1 = ttk.Label(root2)
>     L1.config(text = 'Window2')
>     L1.pack()
> 
>     root2.mainloop()
      ^^^^^^^^^^^^^^^^

The second call to mainloop() is the problem, just remove it and
everything will work as expected. mainloop() must only be called
once per application (for the main Tk() window).

I hope this helps

Michael




More information about the Tkinter-discuss mailing list