Toplevel in Tkinter: prohibition of opening two windows

Say I have a simple code like:

from Tkinter import * root = Tk() app = Toplevel(root) app.mainloop() 

This opens two windows: the Toplevel(root) window Toplevel(root) and the Tk() window Tk() .

Is it possible to open the Tk() ( root ) window from opening? If so, how? I only need pudding. I want this to happen because I am creating a program that will open several windows, all Toplevel root .

Thanks!

+6
source share
1 answer

The withdraw() method removes a window from the screen.
The iconify() method minimizes the window or turns it into an icon.
The deiconify() method will redraw the window and / or activate it.

If you choose withdraw() , make sure you consider a new way to exit the program before testing.
eg.

 from Tkinter import * # tkinter in Python 3 root = Tk() root.withdraw() top = Toplevel(root) top.protocol("WM_DELETE_WINDOW", root.destroy) but = Button(top, text='deiconify') but['command'] = root.deiconify but.pack() root.mainloop() 

The protocol() method can be used to register a function that will be called when the close button of the top-level window is pressed. In this case, we can use destroy() to exit.

+10
source

All Articles