When i am using turtle module to draw a circle with this simple function:
def draw_shape(self):
canvas = Screen()
t = Turtle()
t.circle(self.r)
canvas.exitonclick()
For the first time when i call this function it opens a new window and draw a circle, i click on it to exit and when i try to again call this function from menu in console i got an error:
Original exception was:
Traceback (most recent call last):
File "main.py", line 136, in <module>
main()
File "main.py", line 132, in main
OPTIONS[user_input][1](shapes)
File "main.py", line 48, in handle_sixth_menu_option
t = Turtle()
File "/usr/lib/python3.6/turtle.py", line 3816, in __init__
visible=visible)
File "/usr/lib/python3.6/turtle.py", line 2557, in __init__
self._update()
File "/usr/lib/python3.6/turtle.py", line 2660, in _update
self._update_data()
File "/usr/lib/python3.6/turtle.py", line 2646, in _update_data
self.screen._incrementudc()
File "/usr/lib/python3.6/turtle.py", line 1292, in _incrementudc
raise Terminator
turtle.Terminator
exitonclick
,done
orbye
is only done at the very end of the whole app, and you don't call any further turtle methods. Python Turtle.Terminator even after using exitonclick() is the canonical for this use case. On the other hand, if you want to intentionally open and close multiple windows, this thread can address that use case. – Saltus