Turtle window exit errors

无人久伴 提交于 2019-12-12 02:46:09

问题


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?


回答1:


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...



来源:https://stackoverflow.com/questions/40314146/turtle-window-exit-errors

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!