为什么sublime text 3后自动关闭输出window

Why does sublimetext 3 automatically close the output window after

# ColorSpiralInput.py

import turtle
t = turtle.Pen()
turtle.bgcolor('black')
# Set up a list of any 8 valid Python color names
colors = ['red', 'yellow', 'blue', 'green', 'orange', 'purple', 'white', 'gray']
# Ask the user for the number of sides, between 1 and 8, with a default of 4
sides = int(turtle.numinput('Number of sides', 'How many sides do you want (1-8)?', 
4, 1, 8))
# Draw a colorful spiral with the user-specified number of sides
for x in range(360):
    t.pencolor(colors[x%sides]) # Only use the right number of colors
    t.forward(x*3/sides+x)      # Change the size to match number of sides
    t.left(360/sides+1)         # Turn 360 degrees / number of sides, plus 1
    t.width(x*sides/200)        # Make the pen larger as it goes outward

当我在sublime text 3中运行这段代码时,程序有运行时输出window立即关闭。我无法查看结果然后手动关闭 window。

我已经检查了我的代码,但对此我没有任何解释。我写过其他脚本,但我没有遇到编辑器的相同行为。

难道我必须更改一些设置?

对于控制台中的通用Python turtle 运行ning,最终执行的语句通常是mainloop()或其变体之一,done()exitonclick().这会将控制权交给底层的 tkinter 事件处理程序。

但是,当运行在IDLE、PyCharm、SublimeText 等IDE 下时,规则发生变化并且不一致。有些人需要最后的 mainloop(),有些人不需要,有些人把它变成 no-op。以下是我如何在控制台下将您的程序写入 运行:

# ColorSpiralInputurtle.py

from turtle import Screen, Turtle

# Set up a list of any 8 valid Python color names
COLORS = ['red', 'yellow', 'blue', 'green', 'orange', 'purple', 'white', 'gray']

screen = Screen()
screen.bgcolor('black')

# Ask the user for the number of sides, between 1 and 8, with a default of 4
sides = int(screen.numinput('Number of sides', 'How many sides do you want (1-8)?', 4, 1, 8))

turtle = Turtle()
turtle.speed('fastest')  # because I have no patience

# Draw a colorful spiral with the user-specified number of sides
for x in range(360):
    turtle.pencolor(COLORS[x % sides])  # Only use the right number of colors
    turtle.forward(x * 3 / sides + x)  # Change the size to match number of sides
    turtle.left(360 / sides + 1)  # Turn 360 degrees / number of sides, plus 1
    turtle.width(x * sides / 200)  # Make the pen larger as it goes outward

screen.exitonclick()

如果您的 IDE 拒绝 mainloop()done() and/or exitonclick(),您可以随时使用告诉用户在他们完成查找后输入在你的输出中,并在你的代码中放置一个最终的 input() 调用。