lambda

Martin von Loewis loewis at informatik.hu-berlin.de
Thu May 24 11:40:37 EDT 2001


duncan at NOSPAMrcp.co.uk (Duncan Booth) writes:

> from __future__ import nested_scopes
> import Tkinter
> 
> if __name__ == '__main__':
>     root = Tkinter.Tk()
>     w = Tkinter.Button(root, text='This is a very green button', width= 30, 
> fg='green')
>     
>     buttonList = (
>         ['show', lambda: w.grid(row=0, col=0, columnspan= 5)],
>         ['pink', lambda: w.configure(fg='pink')],
>         ['yellow', lambda: w.configure(bg='yellow')],
>         ['Exit', root.destroy],
>         )

Actually, the same works in any Python version since lambda was
introduced: w is a global variable, and determined as a global in each
of the lambda functions, so you don't need future nested scopes here.

Regards,
Martin




More information about the Python-list mailing list