Python Turtle Graphics(未响应)解决办法 您所在的位置:网站首页 anaconda未响应 Python Turtle Graphics(未响应)解决办法

Python Turtle Graphics(未响应)解决办法

2023-07-17 13:44| 来源: 网络整理| 查看: 265

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 实验室设备网 版权所有