【问题标题】:Python turtle.done() alternatives - how do they differ?Python turtle.done() 替代品 - 它们有何不同?
【发布时间】:2020-06-20 11:48:52
【问题描述】:

我见过 python 乌龟程序使用 turtle.done()turtle.mainloop()turtle.exitonclick() 显然可以互换使用。 The docs 举个例子,他们只使用done()(这将是turtle.done()import turtle

除了turtle.done()(这是我的首选命令)之外,还有什么理由不使用吗?

【问题讨论】:

    标签: python turtle-graphics


    【解决方案1】:

    简短的回答是turtle.done()turtle.mainloop() 的别名,因此两者相同turtle.exitonclick()turtle.mainloop() 一样,但添加了一个事件处理程序(当您单击窗口上的任意位置时程序退出。)

    有关更多详细信息,请参阅这些问题的具体答案:

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

    Python: How to reset the turtle graphics window

    在 Python 2 和 Python 3 之间切换时有一些微妙的选择,因为其中一些从 函数 变为 方法

    【讨论】:

    • 好的,谢谢。不过,我仍然有点困惑 - 是 exitonclick() 在使用单击屏幕上的任意位置时关闭的行为方面的唯一区别,但对于另外两个,他们必须单击右上角的 X要退出的窗口?
    猜你喜欢
    • 2022-12-23
    • 1970-01-01
    • 2014-05-17
    • 2011-04-28
    • 2020-06-11
    • 1970-01-01
    • 2010-11-29
    • 2017-01-18
    • 2018-08-27
    相关资源
    最近更新 更多