我正在尝试做一个程序,让我在一个tkinter窗口上使用turtle绘图。由于某些原因,我不能得到绝对的鼠标坐标。在
我已经完成了root.winfo_pointerx() - root.winfo_rootx()
(和vrootx
)。
我也尝试过:
def mousePos(event):
x,y = event.x , event.y
return x,y
我的代码:
^{pr2}$
我希望光标位于箭头的顶部,但它总是向右和向下。另外,当我向上移动鼠标时,箭头向下移动,反之亦然。在
Tags:
仔细考虑如何设置setworldcoordinate()。-500-500意味着你的世界有1000个大小,窗口大小是500。另外,鼠标指针偏离窗口根-两个绝对坐标都应该使用。你混淆了绝对坐标-鼠标指针和vrootx,两者的比例不同,所以两者之间的距离没有意义。下面的代码可能更接近您的预期。请注意,我将世界坐标设置为与鼠标指针从窗口左上角偏移的绝对坐标相匹配。在
Tkinter的鼠标位置:
海龟的鼠标位置:
^{pr2}$希望这有帮助。在
你有一个不是你自己造成的问题。乌龟一般在画布上使用的方法是乌龟。但是turtle没有固有的“Motion”事件类型,所以您尝试使用原始的
Canvas
事件类型作为替代。这就是冲突。在你自己做的一个问题是,当你在一个快速移动的事件处理程序中时,你需要首先禁用事件处理程序,在退出时重新启用。否则,事件重叠,坏事就会发生。(不谨慎的递归和其他错误。)
我已经重新编写了你的程序如下,我相信你的意图。修复方法是添加missing turtle方法,这样我们就可以留在turtle域内:
相关问题 更多 >
编程相关推荐