Hi Vasilis,

A general method on all widgets;  w.winfo_pointerxy()

   Returns a tuple (x, y) containing the coordinates of the mouse
pointer relative  to w's root window.
   If the mouse pointer isn't on the same screen, returns (-1, -1).

Use this method on you canvas.
If you canvas is scrolled, then you need to adjust these coordinates
(since the top-left corner of the visible canvas may not be (0,0) of
the canvas coordinates)
So do something like:

        x,y=canv.winfo_pointerxy()
        x= canv.canvasx(x)
        y= canv.canvasy(y)

Note also you can bind methods to events
(not only clicks on your canas, but also movement)
When the method is called, it gets an event object as one
parameter, and this event object includes the x and y of the cursor

Mick

I am workin from memory here, so don't tak my word for it.



On Fri, Dec 4, 2009 at 4:53 PM, Vasilis Vlachoudis
<vasilis.vlachou...@cern.ch> wrote:
> Hi all,
>
> I have a canvas with some editable text (with create_text) in it.
> How can I get the cursor coordinates x,y from the canvas?
> The index() function returns only the character index, is there a way to
> convert the position of a character into x,y coordinates or bbox?
>
> Vasilis
>
> _______________________________________________
> Tkinter-discuss mailing list
> Tkinter-discuss@python.org
> http://mail.python.org/mailman/listinfo/tkinter-discuss
>
_______________________________________________
Tkinter-discuss mailing list
Tkinter-discuss@python.org
http://mail.python.org/mailman/listinfo/tkinter-discuss

Reply via email to