How to add callbacks that is the same function with different argument in Tkinter python26?
chen zeguang
czg0002 at gmail.com
Wed May 12 09:40:34 EDT 2010
code is in the end.
I want to print different number when pressing different button.
Yet the program outputs 8 no matter which button is pressed.
I guess it's because the callback function is not established untill the
button is pressed, and i has already reached to 8.
then How to add callbacks that is the same function with different argument?
CODE:
from Tkinter import *
root = Tk()
def func(x):
print x
return
func_en=[]
for i in range(9):
func_en.append(lambda:func(i))
for i in range(9):
func_en[i]()
for i in range(9):
Button(root, text='%d'%i, command=func_en[i]).pack()
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20100512/1b821a86/attachment.html>
More information about the Python-list
mailing list