Tkinter checkbuttons and variables

Gigs_ gigs at hi.t-com.hr
Wed Feb 21 09:50:57 EST 2007


from Tkinter import *

states = []

def onpress(i):
     states[i] = not states[i]


root = Tk()
for i in range(10):
     chk = Checkbutton(root, text= str(i), command=lambda i=i: 
onpress(i))
     chk.pack(side=LEFT)
     states.append(0)
root.mainloop()
print states

after exiting i get everything like it suppose to but when i put command 
like this:
command=lambda: onpress(i)
i got only last checkbutton check.

Why i have to pass this default argument?


btw i have python 2.5
thx



More information about the Python-list mailing list