如何在执行其代码后关闭 Python 海龟窗口? [英] How to close the Python turtle window after it does its code?

查看:313
本文介绍了如何在执行其代码后关闭 Python 海龟窗口?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在用 Python 3.5 编写一个包含海龟图形的简单程序我有一个问题:乌龟工作完成后,用户必须手动关闭窗口.

乌龟工作完成后,有没有办法让窗口编程关闭?

感谢任何帮助.

解决方案

turtle.bye(),又名 turtle.Screen().bye(),关闭一个海龟图形窗口.

通常,缺少 turtle.mainloop() 或其变体之一将导致窗口关闭,因为程序将退出,关闭所有内容.turtle.mainloop() 应该是海龟图形程序中执行的最后一条语句,除非脚本是从 Python IDLE -n 中运行的,这会禁用 turtle.mainloop() 和变体.

turtle.Screen().mainloop()turtle.done()turtle.mainloop() 的变体.>

turtle.exitonclick() 又名 turtle.Screen().exitonclick() 绑定屏幕点击事件来做一个 turtle.bye()code> 然后调用 turtle.mainloop()

I'm working on a simple program in Python 3.5 that contains turtle graphics and I have a problem: after the turtle work is finished the user has to close the window manually.

Is there any way to program the window to close after the turtle work is done?

Any help is appreciated.

解决方案

turtle.bye(), aka turtle.Screen().bye(), closes a turtle graphics window.

Usually, a lack of turtle.mainloop(), or one of its variants, will cause the window to close because the program will exit, closing everything. turtle.mainloop() should be the last statement executed in a turtle graphics program unless the script is run from within Python IDLE -n which disables turtle.mainloop() and variants.

turtle.Screen().mainloop() and turtle.done() are variants of turtle.mainloop().

turtle.exitonclick() aka turtle.Screen().exitonclick() binds the screen click event to do a turtle.bye() and then invokes turtle.mainloop()

这篇关于如何在执行其代码后关闭 Python 海龟窗口?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆