Canvas:如何获取鼠标指针的坐标

Canvas: How to get the coordinates of the mouse pointer

我有一个 canvas 图像(例如 4000x3000 像素)(例如可见 800x600 像素,canvas 总尺寸 4000x3000 像素)结合滚动条。如果用户将 down/right 滚动到图像的右下边缘并单击鼠标按钮,我想获取鼠标指针的坐标(而不是可见的 canvas 大小)。如果代码是

bind .fr.c <ButtonRelease-1> {puts "%x / %y"}

我得到可见的坐标 canvas 例如780/580 虽然图像的坐标是 3970/2970。我怎样才能得到这些坐标?非常感谢。

要从物理坐标中获取逻辑坐标,请使用 canvasxcanvasy 方法。

bind .fr.c <ButtonRelease-1> {
    puts "[%W canvasx %x] / [%W canvasy %y]"
}