海龟图形没有响应

Turtle Graphics Not Responding(海龟图形没有响应)
本文介绍了海龟图形没有响应的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在用Python中的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

这篇关于海龟图形没有响应的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

Leetcode 234: Palindrome LinkedList(Leetcode 234:回文链接列表)
How do I read an Excel file directly from Dropbox#39;s API using pandas.read_excel()?(如何使用PANDAS.READ_EXCEL()直接从Dropbox的API读取Excel文件?)
subprocess.Popen tries to write to nonexistent pipe(子进程。打开尝试写入不存在的管道)
I want to realize Popen-code from Windows to Linux:(我想实现从Windows到Linux的POpen-code:)
Reading stdout from a subprocess in real time(实时读取子进程中的标准输出)
How to call type safely on a random file in Python?(如何在Python中安全地调用随机文件上的类型?)