newbie: binding args in callbacks
Gerhard Haering
gerhard.haering at gmx.de
Wed Jul 10 10:06:55 EDT 2002
In article <3D2C3CAB.BE7084F1 at tds.net>, Edward K. Ream wrote:
> I would like to create a set of Tkinter callbacks that vary only in the
> bindings of a single argument. For example, I would like to do:
>
> for val in vals:
> b = Tk.Button(...,command=self.myCallback(val))
>
> But this doesn't work: it executes callback, rather than returning the
> callback function with the second arg bound to val.
I've no idea about Tkinter at all, but this should accomplish what you
need:
command=lambda: self.myCallback(val)
I don't know for sure, but I think this needs nested scopes. So if you're
using Python 2.1, be sure to "from __future__ import nested_scopes". In
Python 2.2, this is the default.
Gerhard
--
mail: gerhard <at> bigfoot <dot> de registered Linux user #64239
web: http://www.cs.fhm.edu/~ifw00065/ OpenPGP public key id 86AB43C0
public key fingerprint: DEC1 1D02 5743 1159 CD20 A4B6 7B22 6575 86AB 43C0
reduce(lambda x,y:x+y,map(lambda x:chr(ord(x)^42),tuple('zS^BED\nX_FOY\x0b')))
More information about the Python-list
mailing list