[Tkinter-discuss] tkinter and cursor

John McMonagle jmcmonagle at velseis.com
Fri Sep 2 07:48:56 CEST 2011

On 02/09/11 13:59, ÊØÖê´ýÍÃ wrote:

> you can get a  figure  with the program, when you move mouse on the canvas (figure),you can see the coordinate on the  right corner , i want to make it in tkinter,there is no "move click in the canvas" event in tkinter,how to make it in tkinter??

You can use the "<Motion>" event.  You also should be converting the
event.x and event.y to canvas coordinates.  This is especially important
when your canvas also includes scrollbars.

So, using your code from previous posts, from the myprint function onwards,

def  myprint(event):
    # convert the event coordinates to canvas coordinates
    x = canvas.canvasx(event.x)
    y = canvas.canvasy(event.y)

    # find the poistion in the top right corner of your canvas widget
    # less a little bit so as to see the displayed text
    cx = canvas.winfo_width() - 10
    cy = 10

    # delete previous displayed text

    # display the coordinates
    canvas.create_text(cx,cy,anchor=E, text='%d,%d' % (x,y), tags='coords')

canvas.bind("<Motion>", myprint)


This will display the canvas coordinate in the top right corner of the
canvas widget.

Suggested reading on Canvas:


Suggested reading on events:




This message has been scanned for viruses and
dangerous content by MailScanner, and is
believed to be clean.

More information about the Tkinter-discuss mailing list