我最近开始使用 Python 中的 turtle 模块,我承认,我是一个彻头彻尾的新手。我一直无法让 turtle 在其中进行绘图的图形窗口保持打开状态。即使我尝试运行像这样简单的东西:
import turtle
wn = turtle.Screen()
tur = turtle.Turtle()
tur.forward(50)
我得到的只是 Python 启动器图标在我的停靠栏上出现一瞬间然后关闭。感谢任何帮助,顺便说一句,我正在 Aptana Studio 3 中执行此操作。
最佳答案
另外,你不妨试试
turtle.mainloop()
在我看来,这比 Tk 稍微好一点。
来自 the docs for turtle.mainloop()
:
Starts event loop - calling Tkinter’s mainloop function. Must be the last statement in a turtle graphics program. Must not be used if a script is run from within IDLE in -n mode (No subprocess) - for interactive use of turtle graphics.
turtle.done()
是 turtle.mainloop()
的别名。
关于Python Turtle 图形窗口仅短暂打开然后关闭,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19018243/