为什么乌龟一直说"an exception has been raised"?

Why does turtle keep saying "an exception has been raised"?

使用 turtle 我创建了一个地图函数:

def loadStreetOne(direction):
    wn = turtle.Screen()
    wn.setup(height = 300, startx = 0, starty = -1)
    turtle.title("Map")
    turtle.bgcolor("white")
    player = turtle.Turtle()
    drawer = turtle.Turtle()
    player.color("red")
    drawer.hideturtle()
    drawer.penup()
    drawer.goto(-312,-100)
    player.penup()
    if direction == "left" or direction == "Left": player.goto(-300,0)
    elif direction == "right" or direction == "Right":
        player.goto(300,4)
        player.lt(90)
    drawer.pendown()
    drawer.color("blue")
    drawer.goto(307,-100)
    drawer.penup()
    drawer.goto(-312,100)
    drawer.pendown()
    drawer.goto(307,100)
    turtle.color('black')
    style = ('Courier', 30)
    turtle.write('Street', font=style, align='center')
    turtle.hideturtle()
    npc1 = turtle.Turtle()
    npc2 = turtle.Turtle()
    npc1.penup()
    npc2.penup()
    npc1.goto(-120,100)
    npc1.rt(90)
    npc2.goto(120,100)
    npc2.rt(90)
    return player, npc1, npc2

当玩家完成交互后,我使用这个函数让角色走到另一边,然后关闭乌龟window:

def arriveOtherSide(player, direction):
    player.speed(2)
    if direction == "left": player.goto(300, 0)
    elif direction == "right": player.goto(-300, 0)
    time.sleep(1)
    turtle.bye()

当我第一次调用它时一切正常:

player, npc1, npc2 = loadStreetOne("left")

我对第二个函数做了同样的事情,它也工作正常:

arriveOtherSide(player, "left")

但是当我再次加载同一条街道并使用完全相同的行再次调用该函数后,它只是返回了一个错误:

Traceback (most recent call last):
  File "C:\Users\surui\OneDrive\Desktop\Study\Computer Engineering\Graded Work\Rightfully\Rightfully\setup.py", line 50, in <module>
    player, npc1, npc2 = loadStreetOne("left")
  File "C:\Users\surui\OneDrive\Desktop\Study\Computer Engineering\Graded Work\Rightfully\Rightfully\setup.py", line 8, in loadStreetOne
    player = turtle.Turtle()
  File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python37_64\lib\turtle.py", line 3816, in __init__
    visible=visible)
  File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python37_64\lib\turtle.py", line 2557, in __init__
    self._update()
  File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python37_64\lib\turtle.py", line 2660, in _update
    self._update_data()
  File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python37_64\lib\turtle.py", line 2646, in _update_data
    self.screen._incrementudc()
  File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python37_64\lib\turtle.py", line 1292, in _incrementudc
    raise Terminator
turtle.Terminator

我的程序是这样的:

import turtle
import time
def loadStreetOne(direction):
    wn = turtle.Screen()
    wn.setup(height = 300, startx = 0, starty = -1)
    turtle.title("Map")
    turtle.bgcolor("white")
    player = turtle.Turtle()
    drawer = turtle.Turtle()
    player.color("red")
    drawer.hideturtle()
    drawer.penup()
    drawer.goto(-312,-100)
    player.penup()
    if direction == "left" or direction == "Left": player.goto(-300,0)
    elif direction == "right" or direction == "Right":
        player.goto(300,4)
        player.lt(90)
    drawer.pendown()
    drawer.color("blue")
    drawer.goto(307,-100)
    drawer.penup()
    drawer.goto(-312,100)
    drawer.pendown()
    drawer.goto(307,100)
    turtle.color('black')
    style = ('Courier', 30)
    turtle.write('Street', font=style, align='center')
    turtle.hideturtle()
    npc1 = turtle.Turtle()
    npc2 = turtle.Turtle()
    npc1.penup()
    npc2.penup()
    npc1.goto(-120,100)
    npc1.rt(90)
    npc2.goto(120,100)
    npc2.rt(90)
    return player, npc1, npc2

def arriveOtherSide(player, direction):
    player.speed(2)
    if direction == "left": player.goto(300, 0)
    elif direction == "right": player.goto(-300, 0)
    time.sleep(1)
    turtle.bye()

player, npc1, npc2 = loadStreetOne("left")
arriveOtherSide(player, "left")
time.sleep(3)
player, npc1, npc2 = loadStreetOne("left")
arriveOtherSide(player, "left")

有谁知道为什么以及如何解决这个问题?

turtle.bye() 永远关闭乌龟 window。调用此函数后无法绘图。删除该行。