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)
preguntado el 27 de agosto de 11 a las 21:08
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.
Tú tienes que decir
turtle.done() cuando termines.
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.
Hope that helps (for you or anyone else reading this),
Just add a call to exitonclick at the end. The Turtle class is implemented using Tkinter and
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()
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() # <------------
done() or something that shows python that you want to exit the turtle window
It has some problem with IDLE. It will work if run from python command line
I thought the trick to closing the turtle program was to rename the 'turtle' module and store it as a new object, then call the .done() method, or .exitonclick() method, for example:
from turtle import * import turtle #make a square for i in range(4): turtle.forward(100) turtle.left(90) turtle.forward(100) turtle.left(90) turtle.forward(100) turtle.left(90) turtle.forward(100) turtle.done()
Or alternatively, something like:
from turtle import * import turtle as t #draw a right angle for i in range(4): t.forward(100) t.left(90) t.forward(100) t.exitonclick()
Simply importing the 'turtle' module on its own will not work. Use the 'from turtle import *' wildcard. Then you'll be able to use the call functions such as forward(), or left() without having to use any prefix or 'object_name.forward()' for example. So long as you finish the code with a simple done() or exitonclick() command, it works:
from turtle import * forward(100) shape('turtle') right(90) forward(100) right(90) forward(100) right(90) forward(100) done()
I tested lots of things for this problem myself as I faced same problem.
So what I found after searching many resources was this:
NB. This problem happens for windows users when the clic on the turtle graphic window.
First, I found spyder environment very useful
Second, this line works just fine:
this would end the execution without any need of clicking.
Of course anyone needs to see what is happening on the window, so I suggest adding this:
import time import turtle <your code on turtle> time.sleep(5) Turtle.bye()
remember to write Turtle with capital t.
add the following line at the end of your code :
¡Eso debería resolver tu problema!
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:
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.
I've come across your problem ever,and then I try to create a shortcut for IDLE as follow(not forget the " -n"):
And launch the IDLE by the shortcut,type yr code and enjoy!FYI.