Turtle Graphics Not Responding

回眸只為那壹抹淺笑 提交于 2019-11-30 07:06:38
aengelberg

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

arevirlegna

Just add a call to exitonclick at the end. The Turtle class is implemented using Tkinter and exitonclick() invokes mainloop() which will keep the turtle window open until you click anywhere in the canvas. So, a simple program looks like this:

from turtle import *
#make a square
for _ in range(4):
   forward(100)
   left(90)
exitonclick()

Enjoy!

recursive recursion

Add a mainloop() or exitonclick() or done() or something that shows python that you want to exit the turtle window

Joseph Welt

I'm using python 3.6.0 and ran into the same issue. The turtle.done() after your code block prevents the turtle graphic window from becoming unresponsive.

import turtle 

for _ in range(5):
    turtle.forward(100)
    turtle.right(360/5)

turtle.done() # <------------
Sahba

add the following line at the end of your code :

wait_for_user()

That should solve your problem!

PyPy

It has some problem with IDLE. It will work if run from python command line

HarryCBurn

I tried the code in my IDLE and it worked perfectly. Do you have an old/slower machine? Although I don't think that's the problem. Try adding a line at the end:

exitonclick()

Its probably just as turtle seem a bit temperamental. Also, If you have found an answer that helped or solved your problem, be sure to upvote and accept the answer (the arrow icon near the question), as the question otherwise displays as unsolved and you will continue getting answers.

-Harry

Chorola

I've come across your problem ever,and then I try to create a shortcut for IDLE as follow(not forget the " -n"):

target:D:\Python27\Lib\idlelib\idle.pyw -n

And launch the IDLE by the shortcut,type yr code and enjoy!FYI.

Jshura

How to fix this in Python 3.4.3:

>>> help(turtle.bye)
Help on function bye in module turtle:

bye()
    Shut the turtlegraphics window.

    Example:
    >>> bye()

when using turtle.done(), the first time will work, but the second time not.

to solve this:

turtle.done()
try:
    turtle.bye()   
except turtle.Terminator:
    pass

from here Problems with running turtle programs in Spyder

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!