Tutle example How to think like a Computer Scientist Turtle Terminator error

  error-handling, python, python-turtle

I am a relative beginner to programming and was studying using how to think like a computer scientist. When completing one of the examples, I consistently run into the error of turtle.Terminator.

import time

def show_poly():
    try:
        import turtle
        win = turtle.Screen() # Grab/create a resource e.g. a window
        tess = turtle.Turtle()
    
        # This dialog could be cancelled 
        # or the conver to int might fail, or n might be zero.
    
        n = int(input("How many sides do you want in your polygon?"))
        angle = 360 / n
    
        for i in range(n): # Draw the polygon
            tess.forward(10)
            tess.left(angle)
        time.sleep(3)
    finally:
        win.bye() # Close the turtle's window

show_poly()
show_poly()
show_poly()

I receive this error

Traceback (most recent call last):
  File "/Users/rohanbansal/mu_code/turtlefinally.py", line 
24, in <module>
    show_poly()
  File "/Users/rohanbansal/mu_code/turtlefinally.py", line 8, in show_poly
    tess = turtle.Turtle()
      File "/Applications/Mu Editor.app/Contents/Resources/Python/lib/python3.8/turtle.py", line 3813, in __init__
RawTurtle.__init__(self, Turtle._screen,
  File "/Applications/Mu Editor.app/Contents/Resources/Python/lib/python3.8/turtle.py", line 2557, in __init__
self._update()
  File "/Applications/Mu Editor.app/Contents/Resources/Python/lib/python3.8/turtle.py", line 2660, in _update
self._update_data()
  File "/Applications/Mu Editor.app/Contents/Resources/Python/lib/python3.8/turtle.py", line 2646, in _update_data
self.screen._incrementudc()
   File "/Applications/Mu Editor.app/Contents/Resources/Python/lib/python3.8/turtle.py", line 1292, in _incrementudc
raise Terminator
turtle.Terminator

When trying to deal with issue/ de-bugging, I found that the error was with the creation of the next turtle (ie. After the first show_poly() occurs, the next time turtle.Turtle occurs, it leads to a turtle.Terminator error).

I included the import turtle into the definition of show_poly, as I found on stack overflow that this was a potential solution. Any help would be much appreciated

Source: Python Questions

LEAVE A COMMENT