How to show a window that was hidden using "withdraw" method?
Asked Answered
E

1

11

I would like to show a window after I called withdraw.

The following is my current code:

from Tkinter import *

def callback():    
    global root
    root.withdraw()
    win2 = Tk()

root = Tk()
Label(root,text='this is a window').pack()
Button(root,text='withdraw',command=self.callback).pack()
mainloop()

As soon as I press the button, the window disappears much as I want it, and another window appears and everything works great. How do I get the first window back, in the same state as it was before?

Evert answered 12/4, 2013 at 9:29 Comment(2)
One important detail: callback functions are not subprocesses. They run on the same thread than the Tkinter code, and the GUI freezes if they take too long. If it was a subprocess, you couldn't access global variables from that function.Loomis
You should never create two instances of Tk -- Tkinter simply isn't designed to work that way. If you need multiple windows, create instances of Toplevel.Jaffna
E
14

Use the following commands when you want to show the window:

# root.update()  # not required
root.deiconify()

If you want to know more about it, see here.

Evert answered 12/4, 2013 at 9:40 Comment(1)
Does that mean it is not required??Evert

© 2022 - 2024 — McMap. All rights reserved.