Micah
Micah

Reputation: 21

Turtle window exit errors

When I click out of my turtle window it spits 24 lines of errors to the shell.

The error report ends with turtle.Terminator.

turtle.Terminator is not an exception so I can't handle it with try-except.

Is there a base class for all turtle exceptions so I can get rid of these errors?

Upvotes: 0

Views: 1388

Answers (1)

cdlane
cdlane

Reputation: 41925

You want to use the window's native close button (eg. the red X in OSX) to close the window while your turtle code is running. You end up with lots of error messages to the terminal. The following approach allows me to cleanly close the window without error messages:

import turtle

# put all your variable and function definitions here

try:

    # put all the setup code you invoke here

    turtle.exitonclick()  # or mainloop() or done()
except Exception:
    pass

Now when you close the window, you'll get no error messages. Clearly only do this to a finished, fully debugged program otherwise you'll miss error messages you really want to see...

Upvotes: 1

Related Questions