如何加速Python的'龟'功能,并在最后停止冻结 [英] How to speed up python's 'turtle' function and stop it freezing at the end

查看:574
本文介绍了如何加速Python的'龟'功能,并在最后停止冻结的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have written a turtle program in python, but there are two problems.


  1. 对于大数字,它太慢了,I我想知道如何加快龟的速度。

  2. 完成后冻结,点击时表示'没有回复'。

这是我的代码:

This is my code so far:

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中!

By the way: I am on version 3.2!

推荐答案


  1. 设置 turtle.speed 为fas
  2. 使用 turtle.mainloop()功能在没有屏幕刷新的情况下进行工作。

  3. 使用 turtle.tracer(0,0)禁用屏幕刷新然后在最后执行 turtle.update()

  1. Set turtle.speed to fastest.
  2. Use the turtle.mainloop() functionality to do work without screen refreshes.
  3. Disable screen refreshing with turtle.tracer(0, 0) then at the end do turtle.update()

这篇关于如何加速Python的'龟'功能,并在最后停止冻结的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆