themetman
themetman

Reputation: 61

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

I am creating a program using Python 2.7 and GTK3+ with Glade under Linux. I have an Image object and want to run a method when the image is clicked. Here is the object

<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>

and the event handler

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

I cannot find any event other than the "button-press-event" which might work. I have some buttons which work fine when clicked, why does this method not work when I click the image?

Upvotes: 1

Views: 1235

Answers (1)

ptomato
ptomato

Reputation: 57890

A Gtk.Image is just a passive component, it doesn't react to button clicks. The simplest thing to do is to put it inside a Gtk.EventBox and react to clicks on the event box.

Upvotes: 3

Related Questions