Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Turtle graphics - How do I control when the window closes?

I have a small python script which draws some turtle graphics. When my script has finished running, the turtle screen automatically closes, so to be able to see the graphics for a while I have to use time.sleep(5) at the end of the script to delay the closing.

Is there any way I can make this more dynamic, i.e. tell python that I want to control the closing of the window myself? I don't mind if the script can't do anything else while waiting for my command, but I'd prefer if I didn't have to go to the console for a read() or something. Ideally, the canvas should stay open even after the script finishes running, but I am OK with a solution that halts the script until I close the window that holds the canvas (or click the canvas, or whatever...).

How do I accomplish this?

like image 205
Tomas Aschan Avatar asked Jun 04 '11 04:06

Tomas Aschan


People also ask

How do I keep turtle screen open in Python?

Bind bye() method to mouseclick on TurtleScreen. If using_IDLE – value in configuration dictionary is False (default value), enter mainloop. If IDLE with -n switch (no subprocess) is used, this value should be set to True in turtle.

What screen method closes the graphics window?

Screen(). bye() , closes a turtle graphics window.


1 Answers

Just use turtle.done() or turtle.Screen().exitonclick() as a last command of your turtle program.

like image 199
hua Avatar answered Sep 20 '22 13:09

hua