Here is my GUI and code shown as below, expected result is:
one -- print 0
two -- print 1
three -- print 2
However, the program prints "2", no matter which check-box get selected. How can I fix it?
from Tkinter import *
root = Tk()
my_list = ['one', 'two', 'three']
cb_value = []
cb = []
def show_index(idx):
print idx
for idx, each in enumerate(my_list):
cb_value.append(IntVar())
cb.append(Checkbutton(root, text=each, variable=cb_value[idx], command=lambda: show_index(idx)))
cb[idx].pack()
root.mainloop()
thanks!