我有这个错误:举起终结者乌龟。终结者

时间:2019-11-27 16:18:55

标签: python turtle-graphics

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

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

为什么会有这种问题? 第一只乌龟很好没问题 但是到第二秒时,我得到了上面的错误。

1 个答案:

答案 0 :(得分:0)

两次用bye()终止turtle之后,您仍会继续使用turtle:

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!")