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

后端 未结 3 1822
慢半拍i
慢半拍i 2020-12-10 13:26

I\'m working on a simple program in Python 3.5 that contains turtle graphics and I have a problem: after the turtle work is finished the user has to close the window manuall

3条回答
  •  半阙折子戏
    2020-12-10 14:13

    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()

提交回复
热议问题