Tkinter/Pmw callback question

Fredrik Lundh fredrik at pythonware.com
Sun Feb 25 18:16:06 EST 2001


Rick Pasotto wrote:
> 'command=' takes the *name* of a function.

not really.   it takes a function object, or any other callable object
(a lambda, bound method, a class instance with a __call__ method,
etc).

> Adding parens changes the *name* to an actual function call. The
> way

one way.

> to get around this is to use the nameless name 'lambda' for the
> name of the function and *it* can call the function you really want.
> So:
>
>    rb = Button(root, text='Run', command='lambda x="junk":barf(x)')

it probably works a bit better if you remove the quotes around
that lambda expression.  otherwise, it's just an ordinary string,
and strings cannot be called.

Cheers /F





More information about the Python-list mailing list