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)
turtle. reset() Does a turtle. clear() and then resets this turtle's state (i.e. direction, position, etc.) turtle.
1 Answer. Please be informed that your main issue is that you've defined your program "turtle.py". #the first matching package named turtle that it finds is your program, "turtle.py". In other words, your program is essentially importing itself and not the turtle graphics module.
Turtle graphics are a great way to introduce kids to coding. With short programs of just five to ten lines of code, kids can create and modify while learning.
Turtle can draw intricate shapes using programs that repeat simple moves. By combining together these and similar commands, intricate shapes and pictures can easily be drawn.
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
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!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With