Tkinter.Button(... command) lambda and argument problem
bearophileHUGS at lycos.com
bearophileHUGS at lycos.com
Fri Sep 15 20:34:44 EDT 2006
In that case you don't need a lambda:
import Tkinter as tk
class Test:
def __init__(self, parent):
buttons = [tk.Button(parent, text=str(x+1),
command=self.highlight(x)) for x in range(5)]
for button in buttons:
button.pack(side=tk.LEFT)
def highlight(self, x):
print "highlight", x
root = tk.Tk()
d = Test(root)
root.mainloop()
Bye,
bearophile
More information about the Python-list
mailing list