[Tkinter-discuss] [Fwd: Re: lambda function to simplify]

Michael Lange klappnase at web.de
Sat Dec 18 19:15:40 CET 2010


Hi,

Thus spoketh "Michael O'Donnell" <michael.odonnell at uam.es> 
unto us on Sat, 18 Dec 2010 18:53:01 +0100:

> Hi Michael,
> 
> >    self.root.protocol('WM_DELETE_WINDOW', lambda : greeting(self))
> 
> I've had trouble with lambdas, because variables are not resolved
> at declaration time, but at execution time. WOuld not the following be
> better:
> 
> self.root.protocol('WM_DELETE_WINDOW', lambda w=self : greeting(w))
> 
> ....too tired to actually test your code.

I don't like lambdas too much either :)
In this case both variants will work, still I'd prefer to wrap the
lambbda into a class method, but that's just a matter of taste.

Regards

Michael


.-.. .. ...- .   .-.. --- -. --.   .- -. -..   .--. .-. --- ... .--. . .-.

The heart is not a logical organ.
		-- Dr. Janet Wallace, "The Deadly Years", stardate 3479.4


More information about the Tkinter-discuss mailing list