[Tkinter-discuss] Hide/Show using withdraw()/deiconify()

Amit Finkler amit.finkler at gmail.com
Sun Sep 7 10:57:48 CEST 2008


Hi,



I want to have a button in my root window which either hides or shows a
different (Toplevel) window. I wrote the following code (assume import
Tkinter)



    RunFrame             = Tkinter.Frame(win1, bd = 2, relief = 'groove')


    MODES = [
              ("2D-On",  "1"),
          ("2D-Off", "2"),
        ]


    hs    = Tkinter.StringVar()
    hs.set("1")


    for text, mode in MODES:
        Run2D = Tkinter.Radiobutton(RunFrame, text = text, variable =
    hs, value = mode, command = Hide_Show_2D(hs))
        Run2D.pack(side = 'left')



where



    def Hide_Show_2D(value):
        """ Hide or show the 2D scan windows (win4) using withdraw() and
    deiconify() """


        if value == '2':
            win4.withdraw()
        else:
            win4.deiconify()



and



    win1             = Tkinter.Tk()
    win1.title('Control Panel')


    win4             = Tkinter.Toplevel()
    win4.title('2D scans panel')



Not surprisingly, when I push the Run2D button, nothing happens...


What am I doing wrong?



Your help will be greatly appreciated,



Amit Finkler.





More information about the Tkinter-discuss mailing list