PyGTK Notebook button_press_event connection

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Luigi

    #1

    PyGTK Notebook button_press_event connection

    Hi all!

    I have an application that uses a gtk.Notebook to show the content of a
    GUI. Each page of it has a gtk.Label with a text that explains the
    content. Each page is added to the notebook with the method
    append_page(chi ld, tab_label=None) , passing a gtk.Label instance as
    tab_label variable.

    Now I'd like to connect to the button_press_ev ent of the gtk.Label a
    function call. I've done something like this:

    <code>

    notebook = gtk.Notebook()
    ....
    child = gtk.Frame()
    ....
    label = gtk.Label('Any text')
    label.connect(' button_press_ev ent', a_function)
    ....
    notebook.append _page(child, label)

    </code>

    But the button_press_ev ent event is not intercepted (nothing happens
    when I click on the tab label).

    Any idea to solve this question?

    Thanks

    Luigi

  • Johan Dahlin

    #2
    Re: PyGTK Notebook button_press_ev ent connection

    > <code>[color=blue]
    >
    > notebook = gtk.Notebook()
    > ...
    > child = gtk.Frame()
    > ...
    > label = gtk.Label('Any text')
    > label.connect(' button_press_ev ent', a_function)
    > ...
    > notebook.append _page(child, label)
    >
    > </code>
    >
    > But the button_press_ev ent event is not intercepted (nothing happens
    > when I click on the tab label).[/color]

    A gtk.Label does not have a gdk window (as in the windowing system of gtk+),
    so it cannot listen to events. A workaround is to put it in an eventbox:

    eventbox = gtk.EventBox()
    eventbox.set_ev ents(gtk.gdk.BU TTON_PRESS_MASK )
    eventbox.connec t('button-press-event', callback)

    label = gtk.Label()
    eventbox.add(la bel)

    notebook.append _page(..., eventbox)

    Perhaps you should subscribe to the PyGTK mailing list[1] though, where this
    kind of question is more appropriately asked

    [1]: http://www.daa.com.au/mailman/listinfo/pygtk

    Johan Dahlin

    Comment

    Working...