I’m loading an image via imshow() which allows me to track coordinates of the mouse as I hover it over the image. I’m using the coordinates as inputs for some other stuff.
I wonder if it’s possible instead to display an image, click somewhere on it, and have some code pick up and store the coordinates of the pixel I clicked on.
Some similar questions I found here mention use of Gtk but I’m wondering if there is a more “natural” way to accomplish this.
I’m only asking pointers and references for what’s suitable for this purpose, not for anyone to do this for me. Thank you in advance.
This piece of code plots a red cross on the position you click in the image:
using GLMakie
img = rand(50,50)
fig, ax = image(img)
display(fig)
on(events(fig).mousebutton, priority=0) do event
if event.button == Mouse.left
x, y = mouseposition(ax.scene)
scatter!(ax, [x], [y], marker='+', color=:red, markersize=30)
end
end