[Tutor] lambda and creating GUIs
Alan Gauld
alan.gauld at freenet.co.uk
Fri Jun 16 12:16:53 CEST 2006
>I have been reading though the PyGTK tutorial.
> Can anyone explain how lambda is being used in this
> statement:
>
> button.connect("clicked", lambda w: gtk.main_quit())
lambda is being used to create an anonymous function.
The code could be rewritten like this:
def f(w): gtk.main_quit()
button.connect("clicked", f)
lambda simply saves cluttering up the code with lots of tiny function
derfinitions which are never referred to apart from in the binding
operation.
You can read about lambdas in the functional programming topic in my
tutor
HTH,
Alan Gauld
Author of the Learn to Program web site
http://www.freenetpages.co.uk/hp/alan.gauld
More information about the Tutor
mailing list