Tkinter Option (Radio) Buttons
John Grayson
johngrayson at home.com
Mon Jul 10 14:44:29 EDT 2000
In article <Haoa5.50544$dF.2046832 at news1.rdc1.il.home.com>,
"dsavitsk" <dsavitsk at e-coli.net> wrote:
> If i have 3 option buttons created like in Interface() below I am able
to
> use Value() to determine which button is selected, Is there a bit of
code
> that i could add to Value() to disable certain buttons (i don't need
the
> if...elif's, just how to disable an option of my choosing.) or a
better way
> to do this.
>
> >>> def Value():
> ... global CnType
> ... print CnType.get()
>
> >>> def Interface():
> ... CnType = IntVar()
> ... CnType.set(0)
> ... fm = Frame()
> ... optTp = Radiobutton(fm5, text='Button 0', variable=CnType,
value=0)
> ... optTp.grid(row=0, column=0, sticky=W)
> ... optTp = Radiobutton(fm5, text='Button 1', variable=CnType,
value=1)
> ... optTp.grid(row=0, column=1, sticky=W)
> ... optTp = Radiobutton(fm5, text='Button 2', variable=CnType,
value=2)
> ... optTp.grid(row=0, column=2, sticky=W)
> ... fm5.pack(side=TOP)
>
> thanks
> doug
>
>
You need to store the widget ID for the radiobuttons (say in a list).
Then, you could simply index into the list to set the state
of the RadioButton...
e.g.
from Tkinter import *
def Value():
global CnType, wList
wList[CnType.get()].configure(state=DISABLED)
def Interface(master):
global CnType, wList
CnType.set(0)
fm5 = Frame(master)
for i in range(3):
optTp = Radiobutton(fm5, text='Button %d' %i, variable=CnType,
value=i, command=Value)
optTp.grid(row=0, column=i, sticky=W)
wList.append(optTp)
fm5.pack(side=TOP)
root = Tk()
CnType = IntVar()
wList = []
global CnType, wList
Interface(root)
root.mainloop()
You can get the idea...
John
Sent via Deja.com http://www.deja.com/
Before you buy.
More information about the Python-list
mailing list