如何让乌龟跟随 Python 中的鼠标光标?

时间:2021-07-29 07:44:58

标签: python python-3.x turtle-graphics

嗨,我是 Python 初学者。我正在用 Python 海龟图形制作一个绘图程序。我在用鼠标控制海龟时遇到了一些问题。

我想乌龟跟随光标而不点击。但是我想让乌龟在我点击鼠标左键时可以画线。

我用谷歌搜索了这个问题。但我找不到答案。

所以这些东西是我代码的一部分。 (如果您需要全部代码,请在评论中告诉我)


import turtle as t

def draw_pen(x, y):

    t.ondrag(None)
    t.pendown()
    t.setheading(t.towards(x, y))
    t.goto(x,y)
    t.ondrag(draw_pen)

def dragging(x, y):
    t.ondrag(None)
    t.penup()
    t.setheading(t.towards(x, y))
    t.goto(x, y)
    t.ondrag(dragging)


t.onscreenclick(draw_pen, 1)
t.ondrag(dragging)

谢谢:)

0 个答案:

没有答案
相关问题