首页 > 解决方案 > 我有这个错误:raise Teminator turtle.Terminator

问题描述

其他人问了这个问题,但它对我没有帮助。我写了这段代码:

import turtle
import time

s = turtle.Screen()
t = turtle.Turtle()

t.pd()
t.pensize(3)
t.speed(10)
t.circle(100)

time.sleep(2)
turtle.bye()

fq = str(input("What shape is it? - "))
fq = fq.lower()
while fq != "circle":
    print("It's not the right shape")
    fq = str(input("What shape is it? - "))
    fq = fq.lower()
print("Good Job!")

s = turtle.Screen()
h = turtle.Turtle()

t.pd()
t.pensize(3)
t.speed(10)

t.goto(50, 0)
t.goto(50, 50)
t.goto(0, 50)
t.goto(0, 0)

time.sleep(2)
s.bye()

sq = str(input("What shape is it? - "))
sq = sq.lower()
while sq != "square":
    print("It's not the right shape")
    sq = str(input("What shape is it? - "))
    sq = sq.lower()
print("Good Job!")

当我到达第二只乌龟时,我遇到了这个问题:

Traceback (most recent call last):
  File "C:/Users/סער 07.סער/Desktop/Python/Shapes.py", line 24, in <module>
    h = turtle.Turtle()
  File "C:\Users\סער 07.סער\AppData\Local\Programs\Python\Python38-32\lib\turtle.py", line 3813, in __init__
    RawTurtle.__init__(self, Turtle._screen,
  File "C:\Users\סער 07.סער\AppData\Local\Programs\Python\Python38-32\lib\turtle.py", line 2557, in __init__
    self._update()
  File "C:\Users\סער 07.סער\AppData\Local\Programs\Python\Python38-32\lib\turtle.py", line 2660, in _update
    self._update_data()
  File "C:\Users\סער 07.סער\AppData\Local\Programs\Python\Python38-32\lib\turtle.py", line 2646, in _update_data
    self.screen._incrementudc()
  File "C:\Users\סער 07.סער\AppData\Local\Programs\Python\Python38-32\lib\turtle.py", line 1292, in _incrementudc
    raise Terminator
turtle.Terminator

为什么我会遇到这种问题?第一个乌龟很好,没有问题,但是当它到达第二个时,我得到了上述错误。

标签: pythonturtle-graphics

解决方案


两次终止 turtle 后,您继续使用 turtle bye()

turtle.bye()
s.bye()

你期望会发生什么?要设置下一个问题,您可以使用类似、、、或screen.reset()简单的命令:screen.clear()turtle.reset()turtle.clear()

from turtle import Turtle

turtle = Turtle()
turtle.hideturtle()
turtle.speed('fastest')
turtle.pensize(3)

turtle.penup()
turtle.sety(-100)  # center circle on screen
turtle.pendown()
turtle.circle(100)

fq = input("What shape is this? - ").lower()

while fq != 'circle':
    print("That's not the right shape.")
    fq = input("What shape is this? - ").lower()

print("Good Job!")

turtle.clear()

turtle.penup()
turtle.goto(-25, -25)  # center square on screen
turtle.pendown()

for _ in range(4):
    turtle.forward(50)
    turtle.left(90)

sq = input("What shape is it? - ").lower()

while sq != 'square':
    print("That's not the right shape.")
    sq = input("What shape is it? - ").lower()

print("Good Job!")

推荐阅读