龟窗出口错误

时间:2016-10-28 22:41:16

标签: python exception-handling turtle-graphics

当我点击我的乌龟窗口时,它会向外壳发出24行错误。

错误报告以turtle.Terminator结尾。

turtle.Terminator不是例外,因此我无法使用try-except处理它。

是否有所有海龟异常的基类,所以我可以摆脱这些错误?

1 个答案:

答案 0 :(得分:1)

您希望在您的乌龟代码运行时使用窗口的本机关闭按钮(例如OSX中的红色X)关闭窗口。您最终会向终端发送大量错误消息。以下方法允许我干净地关闭窗口而没有错误消息:

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

现在,当您关闭窗口时,您将不会收到任何错误消息。显然只对完成的,完全调试的程序执行此操作,否则您将错过您真正想要看到的错误消息...