Python Turtle Graphics(未响应)解决办法 | 您所在的位置:网站首页 › anaconda未响应 › Python Turtle Graphics(未响应)解决办法 |
Python Turtle Graphics(未响应)解决办法
IDE:Spyder 4(Python 3.7) 问题:调用Turtle库绘图后出现未响应 解决办法:在结尾添加turtle.mainloop() 或turtle.done(),还不够! 这两个函数只是停止画笔绘制,但绘图窗体不关闭,手动关闭将无法再次执行代码,无法启动画笔。 所以我们还需在后面添加一句turtle.bye() 关闭窗体。这样我们就能反复运行代码了! 代码示例: import turtle chongyu_turtle = turtle.Turtle() # This is a square! def square(): chongyu_turtle.forward(100) chongyu_turtle.right(90) chongyu_turtle.forward(100) chongyu_turtle.right(90) chongyu_turtle.forward(100) chongyu_turtle.right(90) chongyu_turtle.forward(100) square() turtle.mainloop() turtle.bye() 运行结果: |
CopyRight 2018-2019 实验室设备网 版权所有 |