Home > other >  tkinter canvas only show coordinate if the mouse inside
tkinter canvas only show coordinate if the mouse inside

Time:09-13

I wanted to have a little coordinate locater for my project. but even when I move mouse outside of the canvas it still shows the x an y. how can I limit it so it only works if the mouse is inside of the canvas? thank you in advance enter image description here

def m(canvas):
    grid_xy.configure(text = f'x = {canvas.x} \n y =  {canvas.y}')
    clear_output(wait=True)
window.bind('<Motion>', m)




lbl1 = Label(text = 'X and Y: ')
grid_xy = Label(text = ' ' ,font=f)
grid_xy.place(x=3, y=500)

CodePudding user response:

so I made an obvious mistake and no one point it out.

I should have used :

canvas.bind('<Motion>', m)

to make the mouse movement limited to the canvas

  • Related