[Tutor] Listbox selection
Joe Cox
jgcox39 at highstream.net
Thu Aug 3 20:12:28 CEST 2006
I am still having a problem getting my listbox's binded to the radiobuttons.
I am getting closer.
###Assign each Radiobutton with its own listbox values, show one selected
button and one listbox###
from Tkinter import *
root = Tk()
var = StringVar()
var.set('a')
{ 'Aluminum' : ['Wrought', 'Die cast'],
'Steel' : ['Low Carbon', 'Medium-high carbon','Alloy'] }
def radio_command():
if var.get() == 'a':
# button with value 'a' selected
listbox.insert('a') #here I am trying to put the string starting
with 'Steel' in the listbox
elif var.get() == 'b':
# button with value 'b' selected
listbox.insert('b') #here I am trying to put the string starting
with 'Aluminum' in the listbox
radio_a = Radiobutton(root,text="Steel", variable=var, value='a',
command=radio_command).pack()
radio_b = Radiobutton(root,text="Aluminum", variable=var, value='b',
command=radio_command).pack()
radio_c = Radiobutton(root,text="Cast Iron", variable=var, value='c',
command=radio_command).pack()
radio_d = Radiobutton(root,text="Nickel", variable=var, value='d',
command=radio_command).pack()
radio_e = Radiobutton(root,text="Titaniuim", variable=var, value='e',
command=radio_command).pack()
listbox = Listbox(root)
for item in ():
listbox.insert(END, item)
listbox.pack(side=LEFT, fill=BOTH)
root.mainloop()
Joe Cox
513-293-4830
More information about the Tutor
mailing list