龟图形-如何控制窗口何时关闭? [英] Turtle graphics - How do I control when the window closes?

查看:88
本文介绍了龟图形-如何控制窗口何时关闭?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个小的python脚本,可以绘制一些乌龟图形.当我的脚本运行完毕后,乌龟屏幕将自动关闭,因此要一段时间才能看到图形,我必须在脚本末尾使用time.sleep(5)来延迟关闭.

I have a small python script which draws some turtle graphics. When my script has finished running, the turtle screen automatically closes, so to be able to see the graphics for a while I have to use time.sleep(5) at the end of the script to delay the closing.

有什么办法可以使它更具动态性,即告诉python我想自己控制窗口的关闭?我不介意脚本在等待命令时是否无法执行其他任何操作,但是我更愿意不必在控制台中输入read()之类的东西.理想情况下,即使脚本完成运行后,画布也应保持打开状态,但是我可以采用一种暂停脚本的解决方案,直到关闭包含画布的窗口(或单击画布,或其他...).

Is there any way I can make this more dynamic, i.e. tell python that I want to control the closing of the window myself? I don't mind if the script can't do anything else while waiting for my command, but I'd prefer if I didn't have to go to the console for a read() or something. Ideally, the canvas should stay open even after the script finishes running, but I am OK with a solution that halts the script until I close the window that holds the canvas (or click the canvas, or whatever...).

我如何做到这一点?

推荐答案

只需使用 turtle.Screen().exitonclick() 作为乌龟程序的最后一个命令.

Just use turtle.done() or turtle.Screen().exitonclick() as a last command of your turtle program.

这篇关于龟图形-如何控制窗口何时关闭?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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