[Tkinter-discuss] How to set a constant in lambda

Guilherme Polo ggpolo at gmail.com
Thu Jan 29 18:00:40 CET 2009


On Thu, Jan 29, 2009 at 2:15 PM,  <david.giesen at kodak.com> wrote:
> With lambda, you need to set the value of the variable at the time the
> lambda is created, or else the variable is grabbed from the environment at
> the time the lambda runs.  You can do this by using the variable as a
> default argument.  In your case, change:
>
> XT.append(Button(T,text="Viola:New
> Tab",command=lambda:switch_tabs(whoopsie))
>
> to
>
> XT.append(Button(T,text="Viola:New Tab",command=lambda
> x=Whoopsie:switch_tabs(x))
>

Ah, it looks like you got what he meant.

And to me, when you start having problem with lambda and solves it by
doing lambda bindings, that is a good time to move to real functions.

> ought to do it.
>
> Dave
>
> David J. Giesen | Research Scientist | FPEG US Display OLED Materials R+D
> |
> Eastman Kodak Company | 2/83/KRL MC02216 | Rochester, NY 14650 |
> david.giesen at kodak.com | 1-585-588-0480 Office |
> www.kodak.com
>
>

-- 
-- Guilherme H. Polo Goncalves


More information about the Tkinter-discuss mailing list