Tom*_*han 30 python window-management turtle-graphics
我有一个小的python脚本,绘制一些龟图形.当我的脚本运行完毕后,乌龟屏幕会自动关闭,所以为了能够看到图形一段时间,我必须time.sleep(5)在脚本结束时使用它来延迟关闭.
有什么方法可以使这个更动态,即告诉python我想自己控制窗口的关闭?我不介意在等待我的命令时脚本是否不能做任何其他事情,但我更愿意,如果我不必去控制台找一个read()或什么的.理想情况下,即使脚本运行完毕,画布也应该保持打开状态,但我可以使用一个暂停脚本的解决方案,直到我关闭保存画布的窗口(或单击画布,或者其他......).
我该如何做到这一点?
小智 47
只需使用turtle.done()或turtle.Screen().exitonclick()作为龟程序的最后一个命令.
PAG*_*PAG 20
import turtle
turtle.forward(100)
turtle.left(90)
turtle.forward(100)
# etc.
turtle.getscreen()._root.mainloop() # <-- run the Tkinter main loop
Run Code Online (Sandbox Code Playgroud)
(编辑:turtle.done()如下面的hua所示,不那么难看.)
小智 9
只需使用从turtle模块本身导入的mainloop()函数!
import turtle
#Draw a square
for i in range(4):
turtle.forward(200)
turtle.left(90)
#calling for the mainloop()
turtle.mainloop()
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
59280 次 |
| 最近记录: |