Tkinter.Radiobutton question

Svein Brekke svbrk at
Mon Jan 7 13:06:01 CET 2002

When reading the state variable in the '<ButtonRelease-1>' callback
from a Radiobutton widget, I always get the old variable value, not
the new one.

Try running the following code:

#Start code
from Tkinter import *
import thread,time

class MyRadiobutton(Radiobutton):
    def __init__(self,w,text,variable=None,value=None):
        self.variable = variable
    def onclick(self,e):
        print 'onclick called, variable =',self.variable.get()

root = Tk()
v = StringVar()
r = MyRadiobutton(root,'R',variable=v,value='r')
s = MyRadiobutton(root,'S',variable=v,value='s')
#End of code

This brings up a window with two radiobuttons, named R and S, where R
is selected. Clicking on the S button, prints the following message:

   onclick called, variable = r

I.e. the value picked out in the callback is the old one.

Is there way to read the new value from inside the callback, or do I
have to spawn a new thread for reading the new value after a given
delay (it works, but forces me to add syncronization overhead in my

Svein Brekke

More information about the Python-list mailing list