[pygtk] pygtk at daa.com.au

Alice Marcot alice.inside.mirror at gmail.com
Wed Jun 20 08:35:14 WST 2012


I have a gtk window; a vbox; and I append an image to the vbox. I am trying
to catch mouse click event from the image, but no response. I can catch
mouse click from the window object.

Sample code:



import pygtk
pygtk.require('2.0')
import gtk
import urllib2

class MainWin:

    def destroy(self, widget, data=None):
        print "destroy signal occurred"
        gtk.main_quit()

    def click_event_handler(self, widget, event):
        print "OK" # DOES NOT GET CALLED
#####################################
        print event.x, event.y

    def __init__(self):
        self.window = gtk.Window(gtk.WINDOW_TOPLEVEL)
        self.window.connect("destroy", self.destroy)
        self.window.set_border_width(10)

        self.image = gtk.Image()
        response = urllib2.urlopen('
http://www.dailygalaxy.com/photos/uncategorized/2007/05/05/planet_x.jpg')
        loader = gtk.gdk.PixbufLoader()
        loader.write(response.read())
        loader.close()
        self.image.set_from_pixbuf(loader.get_pixbuf())

        #self.window.add(self.image)
        #self.window.connect("button-press-event", self.click_event_handler)
        self.image.connect("button-press-event", self.click_event_handler)
        self.image.show()
        self.image.set_events(gtk.gdk.EXPOSURE_MASK
                            | gtk.gdk.LEAVE_NOTIFY_MASK
                            | gtk.gdk.BUTTON_PRESS_MASK
                            | gtk.gdk.POINTER_MOTION_MASK
                            | gtk.gdk.POINTER_MOTION_HINT_MASK)

        vbox = gtk.VBox(False, 5)
        button = gtk.Button("Close tab")
        button.show()
        vbox.pack_start(self.image, False, False, 0)
        vbox.pack_start(button, False, False, 0)
        renkMetin = gtk.Entry()
        renkMetin.show()
        vbox.pack_start(renkMetin, False, False, 0)
        vbox.show()
        self.window.add(vbox)
        self.window.connect("destroy", gtk.main_quit)

        self.window.show()
        #self.show_all()

    def main(self):
        gtk.main()

if __name__ == "__main__":
    MainWin().main()
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.daa.com.au/pipermail/pygtk/attachments/20120620/cf6c02a5/attachment.html>


More information about the pygtk mailing list