27

Python でタートル プログラムを作成しましたが、2 つの問題があります。

  1. 数字が大きいと遅すぎるので、どうすればタートルをスピードアップできるのだろうと思っていました。
  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 を使用しています!

4

4 に答える 4

49
  1. に設定turtle.speed()fastestます。
  2. この機能を使用して、turtle.mainloop()画面を更新せずに作業を行います。
  3. turtle.tracer(0, 0)最後に do で画面のリフレッシュを無効にしますturtle.update()
于 2013-04-20T11:59:33.240 に答える
-1

速度の問題は本当に解決できませんが、turtle. done()ファイルの終わりで使用することでフリーズを防ぐことができます、ありがとう

于 2020-11-06T05:24:53.163 に答える