[Tutor] Tkinter radio buttons

Ivan Van Laningham ivanlan@callware.com
Sat, 25 Dec 1999 17:33:51 -0700


Hi All--

Alan Gauld wrote:
> 
> I tried a simple radiobutton app but the suggested
> behaviour didn't happen. I needed to add a command
> function. Is this normal in Tkinter or am I missing
> something?
> 
> The code below doesn't work, but will if you
> uncomment the commented out lines. I thought Tk
> should update the variable automagically...?
> 

If you change the variable from a Python variable to a Tkinter variable,
it will work. ...

<some-variables-are-more-equal-than-others>-ly y'rs,
Ivan

> --------------------------------------
> from Tkinter import *
> 
> rv=0
> 
> def DoIt():
>     print rv
> 
> #def doZero():
> #    global rv
> #    rv = 0
> 
> #def doOne():
> #    global rv
> #    rv = 1
> 
> app = Frame()
> r1 = Radiobutton(app,
>                  variable=rv, value=0,
>                  text="Zero", # command=doZero
>                      )
> r1.pack()
> r2 = Radiobutton(app,
>                  variable=rv, value=1,
>                      text="One", # command=doOne
>                      )
> r2.pack()
> r1.select()
> 
> b = Button(app, text="Showme", command=DoIt)
> b.pack()
> 
> app.pack()
> app.mainloop()
> 
> _______________________________________________
> Tutor maillist  -  Tutor@python.org
> http://www.python.org/mailman/listinfo/tutor

-- 
----------------------------------------------
Ivan Van Laningham
Callware Technologies, Inc.
ivanlan@callware.com
ivanlan@home.com
http://www.pauahtun.org
See also: 
http://www.foretec.com/python/workshops/1998-11/proceedings.html
Army Signal Corps:  Cu Chi, Class of '70
Author:  Teach Yourself Python in 24 Hours
----------------------------------------------