How to close the Python turtle window after it does its code?

别等时光非礼了梦想. 提交于 2019-12-05 02:07:12

turtle.bye(), aka turtle.Screen().bye(), closes a turtle graphics window.

Usually, a lack of turtle.mainloop(), or one of its variants, will cause the window to close because the program will exit, closing everything. turtle.mainloop() should be the last statement executed in a turtle graphics program unless the script is run from within Python IDLE -n which disables turtle.mainloop() and variants.

turtle.Screen().mainloop() and turtle.done() are variants of turtle.mainloop().

turtle.exitonclick() aka turtle.Screen().exitonclick() binds the screen click event to do a turtle.bye() and then invokes turtle.mainloop()

Add tkinter.mainloop()end of file.

example

import turtle
import tkinter as TK

t = turtle.Pen()
for x in range(100):
t.forward(x)
t.left(90)

TK.mainloop()
Victor O

Try exitonclick() or done() at the end of the file to close the window .

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!