0

I have this simple code :

import turtle

s = turtle.Screen()
s.bgcolor('black')

obj = turtle.Turtle()

while True:
    s.update()

And when I close the window, this error comes up :

Traceback (most recent call last):
  File "d:\Visual Studio Code Projects\SortingAlgorithm1\main.py", line 10, in <module>
    s.update()
  File "C:\Users\user\AppData\Local\Programs\Python\Python39\lib\turtle.py", line 1304, in update       
    t._update_data()
  File "C:\Users\user\AppData\Local\Programs\Python\Python39\lib\turtle.py", line 2647, in _update_data 
    self.screen._incrementudc()
  File "C:\Users\user\AppData\Local\Programs\Python\Python39\lib\turtle.py", line 1293, in _incrementudc
    raise Terminator
turtle.Terminator

Is there a way to prevent this?

1 Answers1

0

Replace your final:

while True:
    s.update()

with

s.mainloop()

This while loop seems to be a common introduction to turtle paradigm that is really the wrong thing to do. A complete example:

from turtle import Screen, Turtle

screen = Screen()
screen.bgcolor('black')

turtle = Turtle()
turtle.color('white')

screen.mainloop()
cdlane
  • 40,441
  • 5
  • 32
  • 81