add_command
Alex Martelli
aleax at aleax.it
Sun May 12 13:11:29 EDT 2002
Gorny wrote:
> Hi,
>
> Is there a way of doing something so a menu-command can call
> the callback function with (more) or other arguments??
Sure, you're just looking for a special case of currying as covered in
http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/52549 .
> So you could use instead of this:
>
> status = Menu()
> status.add_command(label='wh00t', command=self.func)
>
> something like:
>
> status.add_command(label='wh00t', command=self.func,
> argskeyword=tuple_containing_args)
If it's a tuple it's unlikely to hold _keyword_ arguments --
more likely it will hold positional ones, no?
Anyway, the special-case you need is something line (in Python 2.2,
or 2.1 with "from __future__ import nested_scopes"):
def curry(func, *args, **kwds):
def curried(): return func(*args, **kwds)
return curried
then you'll call something like
status.add_command(label='wh00t',
command=curry(self.func, *tuple_containing_args))
Alex
More information about the Python-list
mailing list