Python库Turtle.Terminator错误,有人能给我解释一下吗:(

2024-09-19 23:31:15 发布

您现在位置:Python中文网/ 问答频道 /正文

我使用的代码来自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

Tags: inpyliblocal错误lineupdateusers
1条回答
网友
1楼 · 发布于 2024-09-19 23:31:15

您引用的Geeksforgeks示例实现得很差。它使用while True:time.sleep(delay),它们在像turtle这样的事件驱动环境中没有位置。Turtle提供了ontimer()事件来更好地处理这种情况,这将允许您干净地退出程序

这里有一个SO example with the same issue,您应该可以通过搜索找到它

相关问题 更多 >