Skip to main content
 首页 » 编程设计

python之我在 python 2.7 中用循环搞乱 turtle 导入, turtle 不会移动

2025年01月19日12wayfarer

我在 python 2.7 中用循环搞乱 turtle 导入,我只看到屏幕闪烁,程序退出。 这是我的代码:

import turtle 
 
colors = ["red", "orange", "yellow", "green", "blue", "purple"] 
dColors = dict(enumerate(colors)) 
 
 
def circleOfShapes(aTurtle): 
    edges = 3 
    radius = 100 
    for i in range(5): 
        for k in range(360 / 5): 
            aTurtle.color(dColors.get(i)) 
            aTurtle.circle(radius, None, edges) 
            aTurtle.right(5) 
        edges += 1 
        radius -= 10 
 
 
turt = turtle.Turtle() 
turt.shape("arrow") 
 
window = turtle.Screen() 
window.bgcolor("white") 
window.exitonclick() 
 
circleOfShapes(turt) 

这只是我想为我的 child 做一些很酷的东西,让他像我希望的那样在很小的时候就对编程产生兴趣。感谢您的帮助。

请您参考如下方法:

对我而言,代码运行良好。唯一的问题是在您的 for 循环中,您试图在第 11 行中使用 float 进行循环。您需要使用整数。你可以施放它。那应该解决它。希望这会有所帮助。

编辑:代码的另一个问题是 window.exitonclick()

删除或注释掉