gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-01 04:26:51 25 4
gpt4 key购买 nike

我试图让一个对象从屏幕顶部开始,一直到底部并离开屏幕,然后重复。我的老师希望我们使用 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com