【问题标题】:How do you make two turtles draw at once in Python?如何在 Python 中让两只海龟同时绘制?
【发布时间】:2016-10-05 16:34:31
【问题描述】:

如何让两只乌龟同时画图?我知道如何让海龟画画以及如何制作两个或更多,但我不知道如何让它们同时画画。 请帮忙!

【问题讨论】:

  • 你也许可以在自己的线程中运行每只海龟......虽然一般来说这通常不是一个好主意......

标签: python turtle-graphics


【解决方案1】:

这是一个使用计时器事件的极简示例:

import turtle

t1 = turtle.Turtle(shape="turtle")
t2 = turtle.Turtle(shape="turtle")

t1.setheading(45)
t2.setheading(-135)

def move_t1():
    t1.forward(1)
    turtle.ontimer(move_t1, 10)

def move_t2():
    t2.forward(1)
    turtle.ontimer(move_t2, 10)

turtle.ontimer(move_t1, 10)
turtle.ontimer(move_t2, 10)

turtle.exitonclick()

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-09-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-12-31
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多