I have a set of Checkbuttons on root.frame1 and I want to use the selected ones in a subframe of root to make an optionmenu. The approach I have taken is:
import Tkinter as Tk
root = Tk.Tk()
frame1 = Tk.Frame(root)
variables = dict()
s = {'WZ':'1','ZB':'2','RS':'3','CC':'4','CL':'5'}
for k,v in s.iteritems():
variables[k]= Tk.IntVar()
cb = Tk.Checkbutton(frame1, text=v,onvalue=v, offvalue=0, variable=variables[k], anchor=W)
cb.pack(side='top',fill='x')
frame1.pack()
and then when I select some of the checkbuttons, the values in the variables dictionary are still 0:
for k,v in variables.iteritems():
print k,' ',v.get()
which prints out:
'WZ' 0
'ZB' 0
....
I tried to use a list of tuples instead of a dictionary i.e. variables =[('WZ',),...] but still the values don't change. Do you know what is wrong with my code? Please let me know. Thanks Ali
Tk.IntVar()withTk.IntVar(frame1)?