如何将海龟模块与鼠标一起转动

How do I turn the turtle module along with my mouse

我一直想知道乌龟会如何用鼠标转动(就像许多 io 游戏一样)

有命令什么的吗?

方法如下:

import turtle

wn = turtle.Screen() # Create screen
t = turtle.Turtle('turtle') # Create turtle

def drag(x, y): # Define drag function
    t.ondrag(0)
    t.setheading(t.towards(x, y))
    t.goto(x, y)
    t.ondrag(drag)

t.ondrag(drag) # Use function on turtle
wn.mainloop()

输出:

编辑:正如@cdlane 在评论中指出的那样,t.ondrag 方法中的 0 最好是 None,因为前者定义了一个抛出的新事件函数由于受 except Exception: pass.

保护,所以看不到的异常