[Tutor] lambda and creating GUIs

John Fouhy john at fouhy.net
Sat Jun 17 04:53:23 CEST 2006


On 17/06/06, Christopher Spears <cspears2002 at yahoo.com> wrote:
> I understand this:
> >
> > def f(w): gtk.main_quit()
> > button.connect("clicked", f)
> >
> Now my question is what is "w"?  What is being passed
> to the function?

I don't know GTK, but I would guess some kind of event class.  Other
GUIs I've used (Tkinter, wxPython) pass event objects to callbacks,
which contain information like
 - which mouse button was clicked
 - the exact mouse coordinates (relative to the corner of the screen
or the corner of the widget)
 - which key was pressed
etc.

You may know some of the information, some of it may not apply, you
may not care about the rest of it, but you usually get it anyway :-)

In this case, the program doesn't care about any of the extra
information, so it accepts the event, but it does nothing with it.

Try this:

def show(e):
    print e
    print 'Class:', e.__class__
    print 'Members:'
    for attr in dir(e):
        print '%s: %s' % (attr, getattr(e, attr))

button.connect("clicked", show)

-- 
John.


More information about the Tutor mailing list