1

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?

ptomato
  • 56,175
  • 13
  • 112
  • 165
themetman
  • 51
  • 6

1 Answers1

3

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.

ptomato
  • 56,175
  • 13
  • 112
  • 165
  • No need to add "SOLVED" to the title; instead, click the green checkmark. That gives both of us a reward. – ptomato Apr 08 '17 at 07:01
  • Thanks for that, i did read the tutorial, but obviously missed that essential piece if information. I did try to votu you up, but im an not allowed to vote yet. – themetman Apr 10 '17 at 07:43