Keeping Python Turtle Graphics window open

First question from a beginner with PyCharm Edu

I try some simple Python example files and when I run

import turtle
t=turtle.Pen()
t.forward(50)

I see the graph window for only a fraction of second and then it disappears. Is there a way to handle this or should I keep on using the ugly IDLE editor?

Thanks !

3 comments
Comment actions Permalink

Hi Alexis

I'm also just beginning to learn Python and at 70 years old.I have been using the Python IDLE and was surprised to see when using PyCharm that the turtle screen rapidly disappear when the script finished. I work around this by adding two lines of script at the end

import time

time.sleep()

Just put in the delay in seconds within the brackets, I hope this helps, I've no doubt there's a better way.

Brian

5
Comment actions Permalink

I got a solution on stackoverflow somewhere (lost the link)... but the person asked me to add

Tkinter.mainloop()

and it worked.

 

import turtle
import Tkinter


fred = turtle.Pen()
fred.shape("turtle")
fred.forward(100)
fred.circle(100)
fred.color("blue")
fred.circle(-100)
fred.forward(100)
Tkinter.mainloop()



1
Comment actions Permalink

After you write your code you need to type.

turtle.done()

It will keep the window up for as long as you like.

3

Please sign in to leave a comment.