如何在 GTK3 和 Python 2.7 中的图像对象上创建 'Click Event'

How can I create a 'Click Event' on Image object in GTK3 and Python 2.7

我正在使用 Python 2.7 和 GTK3+ 以及 Linux 下的 Glade 创建一个程序。我有一个 Image 对象,想要 运行 单击图像时的方法。 这是对象

<object class="GtkImage" id="imageHiResVisual">
    <property name="visible">True</property>
    <property name="can_focus">False</property>
    <property name="tooltip_text" translatable="yes">Click here to switch between British Isles Image and Ireland</property>
    <property name="hexpand">True</property>
    <property name="vexpand">True</property>
    <property name="stock">gtk-missing-image</property>
    <signal name="button-press-event" handler="on_imageHiResVisual_button_press_event" swapped="no"/>
</object>

和事件处理程序

def on_imageHiResVisual_button_press_event(self, widget, data=None):
    print "I am clicked!"

除了 "button-press-event" 之外,我找不到任何可能有效的事件。 我有一些按钮在点击时可以正常工作,为什么这种方法在我点击图片时不起作用?

A Gtk.Image 只是一个被动组件,它不会对按钮点击做出反应。最简单的做法是将它放在 Gtk.EventBox 中并对事件框上的点击做出反应。