Tkinter.Button(... command) lambda and argument problem
Sat Sep 16 09:11:26 CEST 2006
James Stroud <jstroud at mbi.ucla.edu> writes:
> Actually, lambda is not necessary for event binding, but a closure (if
> I have the vocab correct), is: ...
> def make_it(x):
> def highliter(x=x):
> print "highlight", x
> return highliter
For that version you shouldn't need the x=x:
print "highlight", x
The reason is each time you call make_it, you're creating a new scope
where x has the correct value, and highliter keeps referring to that
scope even after make_it has returned.
More information about the Python-list