我使用的代码来自GeekForgeks网站
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
您引用的Geeksforgeks示例实现得很差。它使用
while True:
和time.sleep(delay)
,它们在像turtle这样的事件驱动环境中没有位置。Turtle提供了ontimer()
事件来更好地处理这种情况,这将允许您干净地退出程序这里有一个SO example with the same issue,您应该可以通过搜索找到它
相关问题 更多 >
编程相关推荐