grantjenks / free-python-games

Free Python Games

Home Page:http://www.grantjenks.com/docs/freegames/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Exception in Tkinter callback when quit life game

liudonghua123 opened this issue · comments

I tried to run the life game via freegames play life. When I click close button of the game window. I got Exception in Tkinter callback.

> freegames play life
Exception in Tkinter callback
Traceback (most recent call last):
  File "C:\Users\Liu.D.H\AppData\Local\Programs\Python\Python311\Lib\tkinter\__init__.py", line 1948, in __call__
    return self.func(*args)
           ^^^^^^^^^^^^^^^^
  File "C:\Users\Liu.D.H\AppData\Local\Programs\Python\Python311\Lib\tkinter\__init__.py", line 861, in callit
    func(*args)
  File "C:\Users\Liu.D.H\AppData\Local\Programs\Python\Python311\Lib\site-packages\freegames\life.py", line 61, in draw
    ontimer(draw, 100)
  File "<string>", line 5, in ontimer
turtle.Terminator

The exception comes from the following code.

def draw():
"""Draw all the squares."""
step()
clear()
for (x, y), alive in cells.items():
color = 'green' if alive else 'black'
square(x, y, 10, color)
update()
ontimer(draw, 100)

And I can catch and pass the exception to make it work.

See also https://hg.python.org/cpython/rev/a43d03cdf38b, https://python-forum.io/thread-25483.html.

commented

I am using miniconda in a macbook. I replicated the error. When I click the close button I got a similar Exception in Twinker Callback:

Traceback (most recent call last): File "/opt/miniconda3/envs/game_of_life/lib/python3.9/tkinter/__init__.py", line 1892, in __call__ return self.func(*args) File "/opt/miniconda3/envs/game_of_life/lib/python3.9/tkinter/__init__.py", line 814, in callit func(*args) File "/Users/johnmosquera/Documents/AI/yt-matthew-berman/pyGameExample/game_of_life.py", line 61, in draw ontimer(draw, 100) File "<string>", line 5, in ontimer turtle.Terminator