When I click on the X (close) button while running a infinite loop of drawing in Turtle graphics, some error messages occurs.
Here is an example:
import turtle
wn = turtle.Screen()
tess = turtle.Turtle()
while True:
    tess.forward(50)
    tess.left(120)
    tess.forward(50)
wn.mainloop()
When I close the window, then the following error message shows up.
Traceback (most recent call last):
  File "/Users/user/Downloads/test.py", line 8, in <module>
    tess.forward(50)
  File "/Users/user/anaconda3/lib/python3.6/turtle.py", line 1637, in forward
    self._go(distance)
  File "/Users/user/anaconda3/lib/python3.6/turtle.py", line 1605, in _go
    self._goto(ende)
  File "/Users/user/anaconda3/lib/python3.6/turtle.py", line 3178, in _goto
    self._pencolor, self._pensize, top)
  File "/Users/user/anaconda3/lib/python3.6/turtle.py", line 545, in _drawline
    self.cv.coords(lineitem, *cl)
  File "<string>", line 1, in coords
  File "/Users/user/anaconda3/lib/python3.6/tkinter/__init__.py", line 2463, in coords
    self.tk.call((self._w, 'coords') + args))]
_tkinter.TclError: invalid command name ".!canvas"
I am wondering how such error messages could be avoided.
Is there any way like using "protocol" method with "WM_DELETE_WINDOW" option of the Tk class from the tkinter module?
 
    