Newbie Tkinter question

Eric Brunel eric.brunel at pragmadev.com
Tue Aug 6 08:49:32 EDT 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')
b1.pack()
b2 = Radiobutton(root, variable=v, text='Two', value='2')
b2.pack()
b3 = Radiobutton(root, variable=v, text='Three', value='3')
b3.pack()

def show():
  print v.get()

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

root.mainloop()
-------------------------------------------------

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).

HTH
-- 
- Eric Brunel <eric.brunel at pragmadev.com> -
PragmaDev : Real Time Software Development Tools - http://www.pragmadev.com



More information about the Python-list mailing list