2

Here is my code:

import os
from turtle import *
sc = Screen()
sc.setup(600,600)
image = os.path.expanduser("~\OneDrive\Desktop\AlienGameImage.gif")
sc.register_shape(image)
t = Turtle()
t.shape(image)
sc.exitonclick()

Whenever I run this program, the first time it comes up with this error (Error below). However, the second time I run it, it runs fine. Error:

Traceback (most recent call last):

  File "C:\Users\hulks\.spyder-py3\untitled0.py", line 14, in <module>
    t = Turtle()

  File "C:\Users\hulks\anaconda3\lib\turtle.py", line 3813, in __init__
    RawTurtle.__init__(self, Turtle._screen,

  File "C:\Users\hulks\anaconda3\lib\turtle.py", line 2557, in __init__
    self._update()

  File "C:\Users\hulks\anaconda3\lib\turtle.py", line 2660, in _update
    self._update_data()

  File "C:\Users\hulks\anaconda3\lib\turtle.py", line 2646, in _update_data
    self.screen._incrementudc()

  File "C:\Users\hulks\anaconda3\lib\turtle.py", line 1292, in _incrementudc
    raise Terminator

Terminator

The error comes from here in turtle.py:

def _incrementudc(self):
    """Increment update counter."""
    if not TurtleScreen._RUNNING:
        TurtleScreen._RUNNING = True
        raise Terminator
    if self._tracing > 0:
        self._updatecounter += 1
        self._updatecounter %= self._tracing

I don't want to have to run this code twice every time so if anyone has a solution, I thank you in advance.

1
  • We don't have enough information to answer this. In turtle.py, line 1292 your code is raising the exception. You need to look here and see why it is doing it. Commented Mar 22, 2021 at 17:07

3 Answers 3

1

Don't call both:

sc.exitonclick()
mainloop()

It's one or the other as exitonclick() simply sets up the exit key event and calls mainloop()

Sign up to request clarification or add additional context in comments.

Comments

0

TurtleScreen._RUNNING is False when the program is executed for the first time, so it will enter the judgment formula and throw a Terminator exception

TurtleScreen._RUNNING is True when the program is executed for the second time, skipping the judgment formula, so it executes smoothly.

Delete raise Terminator, you can solve the problem.

Comments

0

I can see from your filepath that you are running it from spyder. The turtle module uses a class variable TurtleScreen._RUNNING which remains false after a destroy between executions when running in spyder instead of running it as a self contained script. I have requested for the module to be updated.

Meanwhile, work around/working examples

1)

import os
import importlib
import turtle
importlib.reload(turtle)
sc = Screen()
sc.setup(600,600)
image = os.path.expanduser(r"~\OneDrive\Desktop\AlienGameImage.gif")
sc.register_shape(image)
t = turtle.Turtle()
t.shape(image)
sc.exitonclick()

import os
import turtle
sc = Screen()
sc.setup(600,600)
image = os.path.expanduser(r"~\OneDrive\Desktop\AlienGameImage.gif")
sc.register_shape(image)
turtle.TurtleScreen._RUNNING=True
t = turtle.Turtle()
t.shape(image)
sc.exitonclick()

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.