Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
316 views
in Technique[技术] by (71.8m points)

python - Turtle Graphics Not Responding

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.

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)
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.

You have to say turtle.done() when you're done.

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.

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...