Vanilla 1.1.10 is a product of Lussumo. More Information: Documentation, Community Support.
def button_press_callback(widget, event, data ):
print "clicked on" % widget
table.connect("button_press_event", button_press_callback)
img.connect("button_press_event", button_press_callback)
#!/usr/bin/env python
import pygtk
pygtk.require('2.0')
import gtk
import os
class ImageClick(object):
def __init__(self):
self.window = gtk.Window(gtk.WINDOW_TOPLEVEL)
self.window.connect("destroy", self.destroy)
self.window.set_border_width(10)
#get the curront path
self.folder = os.path.abspath(os.path.dirname(__file__))
#create the table
self.table = gtk.Table(1, 1)
#create the event box for the images event
self.event_box = gtk.EventBox()
self.event_box.set_events(gtk.gdk.BUTTON_PRESS_MASK)
self.event_box.connect("button_press_event", self.button_press_callback)
#add the event box to the table
self.table.attach(self.event_box, 0, 1, 0, 1)
#Create the image and add it to the event box
self.img = gtk.Image()
self.event_box.add(self.img)
self.image_file = "char.png"
self.img.set_from_file(os.path.join(self.folder, self.image_file))
self.window.add(self.table)
#show everything
self.table.show()
self.event_box.show()
self.img.show()
# and the window
self.window.show()
def destroy(self, widget, data=None):
gtk.main_quit()
def button_press_callback(self, widget, event, data=None):
if (self.image_file != "char.png"):
self.image_file = "char.png"
else:
self.image_file = "diamond.png"
#Set the new image
self.img.set_from_file(os.path.join(self.folder, self.image_file))
def main(self):
gtk.main()
if __name__ == "__main__":
image_click = ImageClick()
image_click.main()
1 to 5 of 5