I want to get the X and Y coordinates when I click on a DrawingArea. I was looking for some examples and I found a code like the following
import gtk
class Ventana(gtk.Window):
def __init__(self):
super(Ventana, self).__init__()
self.set_title('Test')
self.set_size_request(800, 600)
self.set_position(gtk.WIN_POS_CENTER)
self.connect('destroy', gtk.main_quit)
self.drawing_area = gtk.DrawingArea()
self.drawing_area.set_size_request(780, 500)
self.drawing_area.modify_bg(gtk.STATE_NORMAL, gtk.gdk.color_parse('white'))
self.drawing_area.connect('button-press-event', self.on_drawing_area_button_press)
fixed = gtk.Fixed()
fixed.put(self.drawing_area, 10, 10)
self.add(fixed)
self.show_all()
def on_drawing_area_button_press(self, widget, event):
print event.x, ' ', event.y
def main():
Ventana()
gtk.main()
if __name__ == '__main__':
main()
When I run it, the window appears and the DrawingArea with the white background, but when I click on it, it doesn't print the values of event.x
and event.y
and there are no error messages.
Can anyone tell me what is the correct way to do that?
Thanks for answering.