Radiobutton HELP!!

Howard Lightstone howard at eegsoftware.com
Thu Aug 23 14:21:10 EDT 2001


Rbtns wrote:

> Hi, I'm trying to use Radiobuttons with Tkinter. I've used them before,
> but never two lists of them at one time.  The problem I am having is
> that everytime I make a selection in one radiobutton list, the program
> automatically makes that same selection for the other list. I have
> included sample code to illustrate:
>
> from Tkinter import *
>
> root = Tk()
> root.title('Radio Button Test')
>
> sel1 = -1
> sel2 = -1
>
> menubar = Menu(root)
> sel1menu = Menu(menubar, tearoff=0)
> sel2menu = Menu(menubar, tearoff=0)
>
> for a in range(3):
>
> sel1menu.add_radiobutton(label='Select'+str(a),variable=sel1,value=a)
> for a in range(5):
>
> sel2menu.add_radiobutton(label='Select'+str(a),variable=sel2,value=a)
>
> menubar.add_cascade(label='Select1',menu=sel1menu)
> menubar.add_cascade(label='Select2',menu=sel2menu)
>
> root.config(menu=menubar)
>
> root.mainloop()
>
> If anyone knows how to do this, please don't hesistate to respond. Thank
> you very much.

The problem is that Tkinter does not use Python variables directly.  You
have to use the Tkinter variable class and use those:

sel1 = IntVar()
sel1.set(-1)
sel2 = IntVar()
sel2.set(-1)





More information about the Python-list mailing list