海龟图形无响应
我正在用 Python 中的turtle 包创建图表,它在某种程度上是成功的,除了一个问题.一旦turtle生成了我在代码中的图表,它会导致程序说无响应",最终我必须结束任务.我使用的是 Windows 7.
I am creating diagrams with the turtle package in Python, and it is successful to some extent, except for one problem. Once turtle generates the diagram that I have in code, it causes the program to say "Not responding" and eventually I have to end the task. I am using Windows 7.
你们中有人遇到过这种情况或知道根本原因吗?我尝试完全重新安装 Python,但这似乎并没有影响问题.
Have any of you experienced this or know the root cause? I tried reinstalling Python completely, but that didn't seem to affect the problem.
以下是一些使其无法响应的示例代码:
Here is some example code that will make it fail to respond:
import turtle
from turtle import forward, right, left
forward(50)
我遇到了同样的问题(我在 Win 7 上也是如此,然后我在 Win XP 上遇到了同样的问题),我只是想通了.
I had the same problem (I was on Win 7 as well, and I then got the same problem on Win XP), and I just figured it out.
完成后你必须说turtle.done()
.
既然我知道了这一点,那就更有意义了,因为 Python 不知道乌龟已经完成,它可能正在等待乌龟的另一个命令.
Now that I know this, it makes more sense, because since Python doesn't know that the turtle is done, it's probably waiting for another command for the turtle.
这是我假设您正在使用的库的文档(在 Python 2.7 中).我就是这样想出来的.它说 Python 2.7 但这也适用于 Python 2.5.
http://docs.python.org/library/turtle.html
Here's the documentation (in Python 2.7) of what library I assume you're using. It's how I figured that out. It says Python 2.7 but this also works for Python 2.5.
http://docs.python.org/library/turtle.html
希望对您或其他阅读本文的人有所帮助,
亚历克斯
Hope that helps (for you or anyone else reading this),
Alex