python - 我有这个错误: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
为什么我会遇到这种问题?第一个乌龟很好,没有问题,但是当它到达第二个时,我得到了上述错误。
解决方案
两次终止 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!")
推荐阅读
- spring-boot - Spring Cloud Binder Rabbit 配置文件不起作用
- javascript - 下一个 getStaticPaths 参数的嵌套地图
- c# - C# 等效于 Python 的 itertools.cycle
- cmake - cmake 自定义目标可见性
- docker - Dart/Docker - VSCode | 附加到docker容器的dart进程时如何在本地代码中设置断点
- css - 提高或降低跨度但不占用额外的垂直空间
- sublimetext3 - Sublime Sftp 自动刷新打开的文件
- bash - Bash - 如何存储按目录创建时间戳排序的目录列表
- python - 不再能够在 python 中制作简单的数据框图
- xcode - SwiftUI 菜单选择器导航栏仅显示图标