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

Fredrik Lundh fredrik at pythonware.com
Sun Sep 7 12:29:15 CEST 2008

Amit Finkler wrote:

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

your use of excessive whitespace doesn't exactly make it easier to read 
your code...  I suggest reading PEP 8.

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

when you write


Python will *call* the function, take the return value from the 
function, and pass *that* to the Radiobutton.  try inserting a

     command=lambda: Hide_Show_2D(hs)

("lambda: expression" creates an anonymous function that evaluates the 
expression when called).

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

since "value" is a Tkinter StringVar, you have to replace the test with

     value.get() == '2'

(alternatively, change the lambda to "lambda: Hide_Show_2D(hs.get())")


More information about the Tkinter-discuss mailing list