为何Python Turtle模块中鼠标跟随的海龟会出现偏移?
海龟跟随鼠标移动偏移问题
我正在编写一个让海龟(turtle)跟随鼠标移动的程序,当前代码如下:
import turtle t = turtle.Turtle() canvas = turtle.getcanvas() width = canvas.winfo_width() height = canvas.winfo_height() midpointX = width / 2 midpointY = height / 2 t.speed(0) while True: mouseX, mouseY = canvas.winfo_pointerxy() turtleX = mouseX - midpointX turtleY = (mouseY - midpointY) * -1 t.goto(turtleX, turtleY)
在PyCharm或命令行运行时海龟会出现偏移,但在Replit上运行则无此问题,我使用的是Windows 11系统。当鼠标位于屏幕边缘时,海龟的移动范围如图所示:

内容的提问来源于stack exchange,提问作者sbottingota
相关产品推荐
相关产品推荐

