Newbie Tkinter question

Eric Brunel eric.brunel at
Tue Aug 6 14:49:32 CEST 2002

DR wrote:
> How do I find out if a radiobutton is selected without using the
> bind() method? I need something that works like the get() method with
> the Entry widget.

Here is an example:

from Tkinter import *

root = Tk()
v = StringVar()
b1 = Radiobutton(root, variable=v, text='One', value='1')
b2 = Radiobutton(root, variable=v, text='Two', value='2')
b3 = Radiobutton(root, variable=v, text='Three', value='3')

def show():
  print v.get()

Button(root, text='Show', command=show).pack()


This is what variables are for. The available classes are StringVar, 
IntVar, DoubleVar and BooleanVar.

BTW, that's also the way you should read in entries (using their 
textvariable option, not their get method).

- Eric Brunel <eric.brunel at> -
PragmaDev : Real Time Software Development Tools -

More information about the Python-list mailing list