如何使用 while 循环使 python 中的海龟对象再次出现和消失?
How do I make turtle objects in python appear and disappear again with a while loop?
我试图让一个对象从屏幕顶部开始,一直到底部并离开屏幕,然后重复。我的老师要我们使用 while 循环,那么我该怎么做呢?
如果你假设 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()
我试图让一个对象从屏幕顶部开始,一直到底部并离开屏幕,然后重复。我的老师要我们使用 while 循环,那么我该怎么做呢?
如果你假设 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()