Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python Turtle Graphics Window only Opens Briefly then Closes

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.

like image 773
Randoms Avatar asked Sep 26 '13 02:09

Randoms


People also ask

Why does Python turtle close?

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.

How do I make my turtle window stay in Python?

Just use turtle. done() or turtle. Screen().

How do I reset my python turtle screen?

tur. clear() is used to remove the drawing from the screen and the remaining turtle as it is shown on the screen.


1 Answers

Also, you may want to try

turtle.mainloop()

which in my opinion just works slightly better than with Tk.

like image 173
5813 Avatar answered Oct 22 '22 16:10

5813