You can attach an event handler to one or more mouse events like this:
def my_handler(event):
# some stuff
canvas.events.mouse_release.connect(my_handler)
There are other ways to connect a function like this, but we'll stick with this way. Inside this function you'll want to convert your mouse click position in canvas space to visual space:
def my_handler(event):
if event.button == 1:
# left click
transform = your_image_visual.transforms.get_transform(map_to="canvas")
img_x, img_y = transform.imap(event.pos)[:2]
# optionally do the below to tell other handlers not to look at this event:
event.handled = True
.transforms.get_transform().map(x, y)
to get the pixel location of that mouse event. I don't remember offhand what parameters need to be passed toget_transform
for this to work properly. It could also beimap
(for inverse) instead ofmap
. If you can't figure it out, update your question with a simple example of what you have so far and I'll try to provide a full solution later.