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

Michael O'Donnell michael.odonnell at uam.es
Sat Dec 18 18:53:01 CET 2010


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.

Mick

On Sat, Dec 18, 2010 at 2:53 AM, Michael Lange <klappnase at web.de> wrote:
> Hi,
>
> Thus spoketh craf <prog at vtr.net>
> unto us on Fri, 17 Dec 2010 19:15:39 -0300:
>
>
> (...)
>> My guess is that if the instruction...
>>
>> self.root.protocol('WM_DELETE_WINDOW', lambda:((lambda
>> e,widget=self:greeting(widget))(self.root)))
>>
>> can be shortened to occupy the same line?
>>
>> It's for a better understanding of the code.
>
> Oh yes, I misunderstood you.
> And yes, this line looks a little like a candidate for one of those
> obfuscated python contests ;) In fact right now I stare at it and I'm
> quite amazed that it works at all :) (maybe I should mention that it's 3
> a.m. here).
> I think
>

>
> should do the trick, too.
>
> Regards
>
> Michael
>
>
> .-.. .. ...- .   .-.. --- -. --.   .- -. -..   .--. .-. --- ... .--. . .-.
>
> Captain's Log, star date 21:34.5...
> _______________________________________________
> Tkinter-discuss mailing list
> Tkinter-discuss at python.org
> http://mail.python.org/mailman/listinfo/tkinter-discuss
>


More information about the Tkinter-discuss mailing list