0

I've seen python turtle programs use turtle.done(), turtle.mainloop() and turtle.exitonclick() apparently interchangeably. The docs give an example where they just use done() (which would be turtle.done() with import turtle.

Is there a reason to ever use anything but turtle.done(), which is my preferred command?

Robin Andrews
  • 3,514
  • 11
  • 43
  • 111

1 Answers1

1

The short answer is that turtle.done() is an alias for turtle.mainloop() so the two are identical. The turtle.exitonclick() does what turtle.mainloop() does, but adds an event handler (the program exits when you click anywhere on the window.)

For more detail, see these specific answers to these questions:

How to close the Python turtle window after it does its code?

Python: How to reset the turtle graphics window

There is some subtlety in choice when moving between Python 2 and Python 3 as some of these change from functions to methods.

cdlane
  • 40,441
  • 5
  • 32
  • 81
  • OK, thank's. I'm still slightly confused though - is the only difference in terms of behaviour that `exitonclick()` closes when the used click anywhere on the screen, but with the other two they have to click the `X` in the top-right of the the window to exit? – Robin Andrews Mar 15 '20 at 09:22