我正在尝试通过 Python turtle 获取鼠标位置。一切正常,除了我不能让乌龟跳到鼠标点击的位置。
import turtle
def startmap(): #the next methods pertain to drawing the map
screen.bgcolor("#101010")
screen.title("Welcome, Commadore.")
screen.setup(1000,600,1,-1)
screen.setworldcoordinates(0,600,1000,0)
drawcontinents() #draws a bunch of stuff, works as it should but not really important to the question
turtle.pu()
turtle.onclick(turtle.goto)
print(turtle.xcor(),turtle.ycor())
screen.listen()
据我了解,显示“turtle.onclick(turtle.goto)”的行应该将海龟发送到我单击鼠标的任何位置,但事实并非如此。打印行是一个测试,但它只返回我最后发送海龟的位置,名义上是 (0, 650),尽管这没有重大意义。
我尝试查找教程并在 pydoc 中查找,但到目前为止我还没有成功编写这个。
我感谢您的帮助。谢谢你。
编辑:我需要海龟去点击位置(完成),但我也需要它来打印坐标。