Question

I've got two Canvases displaying images (one is the source, and the other is slightly modified). I'd like to sync both Canvases' cursors, i.e when hovering over one, a cursor will also show on the other in the same position. I've already done this by drawing a custom 'plus' cursor (2 intersecting lines), but I'm not satisfied with the result. Is there a way to 'fake' the mouse hovering over the canvas at a certain position?

Edit: My relevant code, as per request:

self.canvas_image.bind("<Motion>", self.processMouseEvent)

def processMouseEvent(self): 
     self.cursorSync.Sync(event)
Was it helpful?

Solution 2

No, there is no way to have more than one cursor active at a time. Your only option is to simulate a second cursor by either drawing one on the canvas, or using a small widget that you place over the canvas.

OTHER TIPS

The Motion event will have an x,y attribute assigned to it. Why not do something like this, where your cursor could be any object that can be managed by the place geometry manager:

def move_cursor(event):
    cursor.place(x=event.x, y=event.y) # set x,y to cursor

root = Tk()

left = Canvas(root, width=100, height=100, bg='white')
right = Canvas(root, width=100, height=100, bg='black')
left.pack(fill=BOTH, expand=1, side=LEFT)
right.pack(fill=BOTH, expand=1, side=RIGHT)

cursor = Label(right, width=2, bg='red') # create cursor. this could be an image or whatever

left.bind('<Motion>', move_cursor)

mainloop()
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top