tkinter call backs

Timothy R Evans tre17 at pc142.cosc.canterbury.ac.nz
Thu Jul 22 17:50:14 EDT 1999


Dan Pettersson <dan.pettersson at its.uu.se> writes:

> Timothy R Evans wrote:
> > class Command:
> >     def __init__(self, func, *args, **kw):
> >     ...
> >         apply(self.func, args, kw)
> > 
> > Used as following:
> >
> > Button(text='foo', command=Command(myfunction, myarg))
> > 
> > The args (including keywords) that are passed to the Command class are
> > passed on to myfunction when the callback is activated.
> > 
> > I'm wondering if this should be part of Tkinter in some way?
> 
> You can get the same behaviour by using a lambda and defaults
> 
> Button(text='foo', command=lambda e,x=arg1, y=arg2 : function(e,x,y))
> 
> Apologies if all arguments aren't in the write place my TkInter is a bit
> rusty.
> --
> Dan Pettersson				IT Support, Uppsala University, SWEDEN

What bothers me about this method is readability.  Part of python
appeal is clarity and simplicity, using lambdas like this goes quite a 
way to breaking both these principles.  Sorry if this seems a bit
strong, I just have something personal against using lambda.

--
Tim Evans





More information about the Python-list mailing list