[Python-es] Coordenadas del mouse en pygtk

Ramiro rmrsndvl en yahoo.com.ar
Mie Ene 20 02:17:57 CET 2010


Muchas gracias, con esto me las arreglo bien.



saludos





--- El mar 19-ene-10, Arnau Sanchez <pyarnau en gmail.com> escribió:

De: Arnau Sanchez <pyarnau en gmail.com>
Asunto: Re: [Python-es] Coordenadas del mouse en pygtk
Para: "La lista de python en castellano" <python-es en python.org>
Fecha: martes, 19 de enero de 2010, 9:46 pm

On 19/01/10 21:39, Ramiro wrote:

> Lo que quiero hacer es que por medio del mouse, haciendo click sobre la
> imagen y luego moviéndolo pueda ir moviendo la parte visible de la imagen.
> 
> Mis preguntas son:
> ¿cómo puedo saber la posición del mouse?
> ¿cómo saber si hay algún botón presionado?

El procedimiento estándar es envolver el objeto que no recibe eventos -como en este caso gtk.Image- con un gtk.EventBox. Ver:

http://www.pygtk.org/pygtk2tutorial/ch-ContainerWidgets.html#sec-EventBox
http://www.pygtk.org/docs/pygtk/class-gtkeventbox.html

El script podría quedar así:

import gtk

def motion_notify(widget, event):
    print "x=%d y=%d" % (event.x, event.y)
def button_notify(widget, event):
    print "button=%d x=%d y=%d" % (event.button, event.x, event.y)

window = gtk.Window()
box = gtk.EventBox()
image = gtk.Image()
image.set_from_file("a.png")
box.add(image)
window.add(box)

box.add_events(gtk.gdk.POINTER_MOTION_MASK)
box.connect("motion_notify_event", motion_notify)
box.connect("button-press-event", button_notify)
window.show_all()

gtk.main()

-- Desarrollador freelance
http://www.arnau-sanchez.com
_______________________________________________
Python-es mailing list
Python-es en python.org
http://mail.python.org/mailman/listinfo/python-es
FAQ: http://python-es-faq.wikidot.com/



      Yahoo! Cocina

Encontra las mejores recetas con Yahoo! Cocina.


http://ar.mujer.yahoo.com/cocina/
------------ próxima parte ------------
Se ha borrado un adjunto en formato HTML...
URL: <http://mail.python.org/pipermail/python-es/attachments/20100119/062f1a71/attachment.html>


Más información sobre la lista de distribución Python-es