PyGTK Notebook button_press_event connection

Discussion in 'Python' started by Luigi, Jan 24, 2006.

  1. Luigi

    Luigi Guest

    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(child, tab_label=None), passing a gtk.Label instance as
    tab_label variable.

    Now I'd like to connect to the button_press_event 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_event', a_function)
    ....
    notebook.append_page(child, label)

    </code>

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

    Any idea to solve this question?

    Thanks

    Luigi
    Luigi, Jan 24, 2006
    #1
    1. Advertising

  2. Luigi

    Johan Dahlin Guest

    > <code>
    >
    > notebook = gtk.Notebook()
    > ...
    > child = gtk.Frame()
    > ...
    > label = gtk.Label('Any text')
    > label.connect('button_press_event', a_function)
    > ...
    > notebook.append_page(child, label)
    >
    > </code>
    >
    > But the button_press_event event is not intercepted (nothing happens
    > when I click on the tab label).


    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_events(gtk.gdk.BUTTON_PRESS_MASK)
    eventbox.connect('button-press-event', callback)

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

    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
    Johan Dahlin, Jan 24, 2006
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. suz
    Replies:
    6
    Views:
    5,205
    Jason Zheng
    Jul 26, 2004
  2. Thomas G. Marshall
    Replies:
    6
    Views:
    391
    Thomas G. Marshall
    Sep 26, 2005
  3. Replies:
    6
    Views:
    524
    Andrew Thompson
    Nov 4, 2005
  4. Replies:
    2
    Views:
    549
    Chris Uppal
    Feb 28, 2006
  5. F. GEIGER
    Replies:
    4
    Views:
    363
    F. GEIGER
    Oct 1, 2003
Loading...

Share This Page