python - Python 库 Turtle turtle.Terminator 错误,谁能给我解释一下:(
问题描述
我使用的代码来自 geekforgeeks 网站
https://www.geeksforgeeks.org/create-a-snake-game-using-turtle-in-python/
当我关闭龟窗时发生错误我必须在另一个问题中回答,但它仍然对我不起作用
错误描述:
Traceback (most recent call last):
File "c:/Users/Zxed/Documents/1. DOCUMENT/Coding/Python/Game/snake.py", line 156, in <module>
snake()
File "c:/Users/Zxed/Documents/1. DOCUMENT/Coding/Python/Game/snake.py", line 88, in snake
layar.update()
File "C:\Users\Zxed\AppData\Local\Programs\Python\Python38-32\lib\turtle.py", line 1303, in update
t._update_data()
File "C:\Users\Zxed\AppData\Local\Programs\Python\Python38-32\lib\turtle.py", line 2646, in _update_data
self.screen._incrementudc()
File "C:\Users\Zxed\AppData\Local\Programs\Python\Python38-32\lib\turtle.py", line 1292, in _incrementudc
raise Terminator
turtle.Terminator
解决方案
您引用的 GeeksForGeeks 示例实施得很差。它使用while True:
并且time.sleep(delay)
在像turtle这样的事件驱动环境中没有位置。Turtle 提供了ontimer()
事件来更好地处理这种情况,这将允许您干净地退出程序。
这是一个具有相同问题的 SO 示例,您应该可以通过搜索找到该示例。
推荐阅读
- c# - 在 UI 元素设置期间忽略属性设置调用
- json - 将 json 列表发布到烧瓶路由时出现 TypeError
- mysql - 我正在尝试在触发器上使用算术,但我的触发器不起作用
- c# - Swashbuckle 多态性需要鉴别器作为更新时的第一个属性
- java - 我正在开发一个 spring mvc 项目,我想从两个下拉框和一个文本框提交值
- android - 有什么地方可以上传两个要翻译的字符串 xml 文件吗?
- javascript - 检查样本库/文档 Vue JS 中是否出现相同的值
- python - Django没有从CSS文件加载图像
- electron - 如何使用electronjs截屏?
- c# - C# Visual Studio Excel 插件:如何检测 Excel Office 主题更改?