python - 如何使用 while 循环使 python 中的 turtle 对象再次出现和消失?

标签 python turtle-graphics

我试图让一个对象从屏幕顶部开始,一直到底部并离开屏幕,然后重复。我的老师希望我们使用 while 循环,那么我该怎么做呢?

最佳答案

如果您假设 t 是一只 turtle ,help(t) 会为您提供:

 ...
 ...
 |  hideturtle(self)
 |      Makes the turtle invisible.
 |
 |      Aliases: hideturtle | ht
 |
 |      No argument.
 |
 |      It's a good idea to do this while you're in the
 |      middle of a complicated drawing, because hiding
 |      the turtle speeds up the drawing observably.
 |
 |      Example (for a Turtle instance named turtle):
 |      >>> turtle.hideturtle()
 |
 |  ht = hideturtle(self)
 |      Makes the turtle invisible.
 |
 |      Aliases: hideturtle | ht
 |
 |      No argument.
 |
 |      It's a good idea to do this while you're in the
 |      middle of a complicated drawing, because hiding
 |      the turtle speeds up the drawing observably.
 |
 |      Example (for a Turtle instance named turtle):
 |      >>> turtle.hideturtle()
 ...
 ...

类似地,还有一个 showturtle() 方法。

如果你算一下:

import turtle
import time

t = turtle.Turtle()
win = turtle.Screen()

for i in range(100):
    t.fd(100)
    t.hideturtle()
    time.sleep(1)
    t.showturtle()

关于python - 如何使用 while 循环使 python 中的 turtle 对象再次出现和消失?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32983304/

相关文章:

python - 当只有一组时,Groupby apply 会进行不需要的转置

python - opencv python使用houghcircle函数检测不规则形状

python - 将每周时间序列转换为每日(使用比例标准)

python - 在 Python 上运行多个 Turtle Speed

python - 如何控制 turtle 图形窗口的打开和关闭?

python - 碰撞检测程序在 Turtle 中不起作用

python - 在列表中查找子列表的起始和结束索引

python - 在 python 中设计类

python - Python turtle 图形中的连续屏幕点击事件

python - 与功能参数作斗争