如何在python中创建turtle对象并使用while循环再次消失?

时间:2015-10-07 03:26:50

标签: python turtle-graphics

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

1 个答案:

答案 0 :(得分:2)

如果您认为t是海龟,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()