I have recently begun using the turtle module in Python, and I admit, I am a complete novice. I have been having trouble getting the graphics window in which the turtle does its drawing to stay open. Even when I try to run something as simple as this:
import turtle
wn = turtle.Screen()
tur = turtle.Turtle()
tur.forward(50)
all I get is the Python launcher icon to appear on my dock for a split second and close. Any help is appreciated, and I am, by the way, doing this in Aptana Studio 3.
Usually, a lack of turtle. mainloop() , or one of its variants, will cause the window to close because the program will exit, closing everything. turtle. mainloop() should be the last statement executed in a turtle graphics program unless the script is run from within Python IDLE -n which disables turtle.
Just use turtle. done() or turtle. Screen().
tur. clear() is used to remove the drawing from the screen and the remaining turtle as it is shown on the screen.
Also, you may want to try
turtle.mainloop()
which in my opinion just works slightly better than with Tk.
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