[pygtk] Current mouse position

Ricardo Caesar Lenzi ricardo@k1.com.br
Thu, 21 Mar 2002 15:57:15 -0300


Em 21 Mar 2002 11:23:39 -0500 Steve McClure <smcclure@racemi.com>
escreveu:

> On Thu, 2002-03-21 at 11:12, Ricardo Caesar Lenzi wrote:
> > Hi,
> > 
> > How can I get the current mouse position (x,y) in a window, button,
> > drawingarea or any other widget? Is there any signal that can handle
this?
> 
> motion-notify-event?

ok... it works, but:

---------------------------------------------------------

import gtk

w=gtk.GtkWindow()
w.set_usize(300,100)

lb=gtk.GtkLabel("Please, show me the mouse position!")
w.add(lb)

def motion_notify(self, event):
    text="Mouse position is: x=%d y=%d" % (event.x, event.y)
    lb.set_text(text)

# Atention here!
w.add_events(gtk.GDK.MOTION_NOTIFY | gtk.GDK.BUTTON_PRESS)

w.connect("motion_notify_event", motion_notify)
w.connect("destroy", gtk.mainquit)

w.show_all()
gtk.mainloop()

---------------------------------------------------------

Can anyone explain me why if I don't add gtk.GDK.BUTTON_PRESS to the
window, the motion_notify_event signal don't work?

Python 1.5.2, GTK 1.2.8, pygtk 0.6.6

Thanks,
Ricardo.