button-press-event and Gtk.Frame
<p>In a window I have a <code>Gtk.Frame</code> with an image inside it. Now I need show a message when the <code>Gtk.Frame</code> is clicked. Here is my code.</p>

<p>Glade XML:</p>

<pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
&lt;!-- Generated with glade 3.18.3 --&gt;
&lt;interface&gt;
  &lt;requires lib="gtk+" version="3.12"/&gt;
  &lt;object class="GtkWindow" id="window1"&gt;
    &lt;property name="can_focus"&gt;False&lt;/property&gt;
    &lt;child&gt;
      &lt;object class="GtkBox" id="box1"&gt;
        &lt;property name="visible"&gt;True&lt;/property&gt;
        &lt;property name="can_focus"&gt;False&lt;/property&gt;
        &lt;property name="orientation"&gt;vertical&lt;/property&gt;
        &lt;child&gt;
          &lt;object class="GtkFrame" id="frame1"&gt;
            &lt;property name="can_focus"&gt;False&lt;/property&gt;
            &lt;property name="tooltip_text" translatable="yes"&gt;Clique para imprimir&lt;/property&gt;
            &lt;property name="halign"&gt;start&lt;/property&gt;
            &lt;property name="valign"&gt;start&lt;/property&gt;
            &lt;property name="label_xalign"&gt;0&lt;/property&gt;
            &lt;property name="shadow_type"&gt;none&lt;/property&gt;
            &lt;signal name="button-press-event" handler="onFrameClicked" swapped="no"/&gt;
            &lt;child&gt;
              &lt;object class="GtkAlignment" id="alignment1"&gt;
                &lt;property name="visible"&gt;True&lt;/property&gt;
                &lt;property name="can_focus"&gt;False&lt;/property&gt;
                &lt;property name="left_padding"&gt;12&lt;/property&gt;
                &lt;signal name="button-press-event" handler="onFrameClicked" swapped="no"/&gt;
                &lt;child&gt;
                  &lt;object class="GtkImage" id="image1"&gt;
                    &lt;property name="visible"&gt;True&lt;/property&gt;
                    &lt;property name="can_focus"&gt;False&lt;/property&gt;
                    &lt;property name="stock"&gt;gtk-home&lt;/property&gt;
                    &lt;signal name="button-press-event" handler="onFrameClicked" swapped="no"/&gt;
                  &lt;/object&gt;
                &lt;/child&gt;
              &lt;/object&gt;
            &lt;/child&gt;
            &lt;child type="label"&gt;
              &lt;object class="GtkLabel" id="label1"&gt;
                &lt;property name="visible"&gt;True&lt;/property&gt;
                &lt;property name="can_focus"&gt;False&lt;/property&gt;
                &lt;property name="label" translatable="yes"&gt;frame1&lt;/property&gt;
                &lt;signal name="button-press-event" handler="onFrameClicked" swapped="no"/&gt;
              &lt;/object&gt;
            &lt;/child&gt;
          &lt;/object&gt;
          &lt;packing&gt;
            &lt;property name="expand"&gt;False&lt;/property&gt;
            &lt;property name="fill"&gt;True&lt;/property&gt;
            &lt;property name="position"&gt;0&lt;/property&gt;
          &lt;/packing&gt;
        &lt;/child&gt;
        &lt;child&gt;
          &lt;object class="GtkLabel" id="label2"&gt;
            &lt;property name="visible"&gt;True&lt;/property&gt;
            &lt;property name="can_focus"&gt;False&lt;/property&gt;
            &lt;property name="label" translatable="yes"&gt;label&lt;/property&gt;
          &lt;/object&gt;
          &lt;packing&gt;
            &lt;property name="expand"&gt;False&lt;/property&gt;
            &lt;property name="fill"&gt;True&lt;/property&gt;
            &lt;property name="position"&gt;1&lt;/property&gt;
          &lt;/packing&gt;
        &lt;/child&gt;
        &lt;child&gt;
          &lt;object class="GtkEntry" id="entry1"&gt;
            &lt;property name="visible"&gt;True&lt;/property&gt;
            &lt;property name="can_focus"&gt;True&lt;/property&gt;
          &lt;/object&gt;
          &lt;packing&gt;
            &lt;property name="expand"&gt;False&lt;/property&gt;
            &lt;property name="fill"&gt;True&lt;/property&gt;
            &lt;property name="position"&gt;2&lt;/property&gt;
          &lt;/packing&gt;
        &lt;/child&gt;
      &lt;/object&gt;
    &lt;/child&gt;
  &lt;/object&gt;
&lt;/interface&gt;
</code></pre>

<p>Python code:</p>

<pre><code>import gi
gi.require_version('Gtk', '3.0')

from gi.repository import Gtk, Gdk

def on_frame_clicked(widget, event):
    print('Clicked!')

builder = Gtk.Builder.new()
builder.add_from_file('frame_event.glade')
window = builder.get_object('window1')

handlers = {'onFrameClicked': on_frame_clicked}

builder.connect_signals(handlers)

window.show_all()
Gtk.main()
</code></pre>

<p>But, when I click on <code>Gtk.Frame</code> nothing happens. I also tried using the same handler for the <code>image</code> and the <code>label</code> in the <code>frame</code>. Still does not work.
I need capture the double click event, but I know that the start point is the <code>button-press-event</code>.</p>

<p>What am I doing wrong?</p>

<p>There's two requirements for button-press-event to work on a widget:</p>

<ul>
<li>widget must have it's own GdkWindow</li>
<li>widget must have GDK_BUTTON_PRESS_MASK in its event mask</li>
</ul>

<p>Widgets that are not normally used for input do not have a GdkWindow so this won't work with GtkFrame. </p>

<p>My first suggestion is to re-evaluate the need: Users do not expect frames to react to clicking. are you sure you want to surprise your users? Maybe another design would work better?</p>

<p>If your situation really does require the frame to be clickable, you can solve this by adding a GtkEventBox as the parent of the frame. The GtkEventBox does have a GdkWindow so you only need to use <code>widget.add_events()</code> to set the event mask and connect to the button-press-event of the GtkEventBox instead of the frame. You also probably want to set the EventBox invisible with <code>event_box.set_visible_window()</code> but please read the documentation on that function for details.</p>

python gtk