[Tutor] lambda and creating GUIs

John Fouhy john at fouhy.net
Fri Jun 16 03:22:02 CEST 2006


(resending to include Tutor -- sorry for the dupe, Christopher)

On 16/06/06, Christopher Spears <cspears2002 at yahoo.com> wrote:
> 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())


Do you understand what lambda does in general?

Does it help if I rewrite the code like this:

def onQuit(w):
   gtk.main_quit()
button.connect("clicked", onQuit)

?

Provided you get your indentation correct ("def onQuit" and
"button.connect" should be at the same level), and provided you aren't
using the name "onQuit" somewhere else in that method, this code
should be a dropin replacement for the line you quote.

--

John.


More information about the Tutor mailing list