擅长:python、mysql、java
<p>下面是我如何对这个问题进行过度设计(并消除了对<code>global</code>语句的需要):</p>
<pre><code>from turtle import Screen, Turtle
def changeTurtle():
index = shapes.index(turtle.shape()) + 1
shape = shapes[index % len(shapes)]
turtle.shape(shape)
screen.title(shape)
turtle = Turtle()
turtle.shapesize(3)
turtle.shape('classic') # first turtle 'classic' shape
screen = Screen()
screen.title(turtle.shape())
shapes = screen.getshapes()
screen.onkey(changeTurtle, 'n') # press 'n' key
screen.listen()
screen.mainloop()
</code></pre>