gpt4 book ai didi

python - 如何加速python的 'turtle'函数并在最后停止卡住

转载 作者:IT老高 更新时间:2023-10-28 21:06:27 30 4
gpt4 key购买 nike

我用python写了一个turtle程序,但是有两个问题。

  1. 对于较大的数字来说速度太慢了,我想知道如何加快 turtle 的速度。
  2. 它在完成后卡住,点击时显示“没有响应”

这是我目前的代码:

import turtle

#Takes user input to decide how many squares are needed
f=int(input("How many squares do you want?"))
c=int(input("What colour would you like? red = 1, blue = 2 and green =3"))
n=int(input("What background colour would you like? red = 1, blue = 2 and green =3"))

i=1

x=65

#Draws the desired number of squares.
while i < f:
i=i+1
x=x*1.05
print ("minimise this window ASAP")
if c==1:
turtle.pencolor("red")
elif c==2:
turtle.pencolor("blue")
elif c==3:
turtle.pencolor("green")
else:
turtle.pencolor("black")
if n==1:
turtle.fillcolor("red")
elif n==2:
turtle.fillcolor("blue")
elif n==3:
turtle.fillcolor("green")
else:
turtle.fillcolor("white")
turtle.bk(x)
turtle.rt(90)
turtle.bk(x)
turtle.rt(90)
turtle.bk(x)
turtle.rt(90)
turtle.bk(x)
turtle.rt(90)
turtle.up()
turtle.rt(9)
turtle.down()

顺便说一句:我在 3.2 版!

最佳答案

  1. turtle.speed() 设置为 fastest
  2. 使用 turtle.mainloop() 功能无需刷新屏幕即可完成工作。
  3. 使用 turtle.tracer(0, 0) 禁用屏幕刷新,然后在最后执行 turtle.update()

关于python - 如何加速python的 'turtle'函数并在最后停止卡住,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16119991/

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