Python Turtle 图形窗口仅短暂打开然后关闭

标签 python graphics module turtle-graphics

我最近开始使用 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/

相关文章:

python - 如何在Python中获得立方根

java - 保存时需要将帧作为图像保存在指定文件夹中

android - 在 Android Canvas 上绘制位图的一部分

java - Android位图 - 将圆裁剪成半圆

module - R shinyjs 显示/隐藏在模块中不起作用

python - 在后台使用 Selenium

python - 使用 python flask 从数据库中删除行?

python:导入的模块处于不同的上下文中

module - 如何在不同的文件中导入 libs 模块

python - 正则表达式拆分字符串并去除重复字符