Python 字符串回溯错误

Python 字符串回溯错误,python,turtle-graphics,Python,Turtle Graphics,我有一个问题,这似乎是非常基本的,但我不能解决它。。。 当我运行我的代码时,我总是得到一个“回溯(最近一次调用):”错误。 问题似乎出在一根绳子上 我得到的错误代码如下: Traceback (most recent call last): File "<string>", line 250, in run_nodebug File "C:\Users\ThinkPad\Documents\Projekt2k18\No Escape ! V1.8.py", line 122, in

我有一个问题,这似乎是非常基本的,但我不能解决它。。。 当我运行我的代码时,我总是得到一个“回溯(最近一次调用):”错误。 问题似乎出在一根绳子上

我得到的错误代码如下:

Traceback (most recent call last):
File "<string>", line 250, in run_nodebug
File "C:\Users\ThinkPad\Documents\Projekt2k18\No Escape ! V1.8.py", line 122, in <module>
stylo = Stylo()
File "C:\Users\ThinkPad\Documents\Projekt2k18\No Escape ! V1.8.py", line 5, in __init__
Turtle.__init__(self, "mur.gif")
File "C:\EduPython\App\lib\turtle.py", line 3816, in __init__
visible=visible)
File "C:\EduPython\App\lib\turtle.py", line 2557, in __init__
self._update()
File "C:\EduPython\App\lib\turtle.py", line 2660, in _update
self._update_data()
File "C:\EduPython\App\lib\turtle.py", line 2646, in _update_data
self.screen._incrementudc()
File "C:\EduPython\App\lib\turtle.py", line 1292, in _incrementudc
raise Terminator
turtle.Terminator
回溯(最近一次呼叫最后一次):
文件“”,第250行,在run_nodebug中
文件“C:\Users\ThinkPad\Documents\Projekt2k18\No Escape!V1.8.py”,第122行,在
stylo=stylo()
文件“C:\Users\ThinkPad\Documents\Projekt2k18\No Escape!V1.8.py”,第5行,在\uuu init中__
乌龟.uuuu init_uuuuuuuu(self,“mur.gif”)
文件“C:\EduPython\App\lib\turtle.py”,第3816行,在\uuu init中__
可见=可见)
文件“C:\EduPython\App\lib\turtle.py”,第2557行,在\uuu init中__
自我更新()
更新中第2660行的文件“C:\EduPython\App\lib\turtle.py”
自我更新数据()
更新数据中的文件“C:\EduPython\App\lib\turtle.py”,第2646行
self.screen.\u incrementudc()
文件“C:\EduPython\App\lib\turtle.py”,第1292行,在增量UDC中
上升终止符
乌龟,终结者
这是我的密码:

from turtle import Turtle, Screen

class Stylo(Turtle):
    def __init__(self):
        Turtle.__init__(self, "mur.gif")
        self.color("white")
        self.penup()
        self.speed('fastest')

class Joueur(Turtle):
    def __init__(self):
        Turtle.__init__(self, "face.gif")
        self.color("blue")
        self.penup()
        self.speed('fastest')

def haut(self):
    move_to_x = self.xcor()
    move_to_y = self.ycor() + 24
    self.shape("back.gif")
    if (move_to_x, move_to_y) not in murs:
        self.goto(move_to_x, move_to_y)
    scorefn()

def bas(self):
    move_to_x = self.xcor()
    move_to_y = self.ycor() - 24
    self.shape("face.gif")
    if (move_to_x, move_to_y) not in murs:
        self.goto(move_to_x, move_to_y)
    scorefn()

def gauche(self):
    move_to_x = self.xcor() - 24
    move_to_y = self.ycor()
    self.shape("left.gif")
    if (move_to_x, move_to_y) not in murs:
        self.goto(move_to_x, move_to_y)
    scorefn()

def droite(self):
    move_to_x = self.xcor() + 24
    move_to_y = self.ycor()
    self.shape("right.gif")
    if (move_to_x, move_to_y) not in murs:
        self.goto(move_to_x, move_to_y)
    scorefn()

def collision(self, other):
    return self.distance(other) < 5

class Tresor(Turtle):
    def __init__(self, x, y):
        Turtle.__init__(self, "tresor.gif")
        self.penup()
        self.speed('fastest')
        self.goto(x, y)

def destruction(self):
    self.hideturtle()
    self.goto(2000, 2000)

class Forme(object):
    def __init__(self, length, width, color, sides):
        self.length = length
        self.width = width
        self.color = color
        self.sides = sides

def draw(self):
    t = turtle.Pen()


boucle=True
while boucle:       #Boucle menu
    a=int(input("Choisissez la figure à réaliser avec Turtle :\n1. Jouer \n2. Leaderboard \n0. Sortir"))

if a==1:
    fn = Screen()
    fn.bgcolor("black")
    fn.title("No Escape!")
    fn.setup(700, 700)

    IMAGES = ["right.gif", "left.gif", "face.gif", "back.gif", "tresor.gif", "mur.gif", "sol.gif"]

    for image in IMAGES:
        # On ajoute l'image a notre labyrinthe.
        fn.addshape(image)

    POLICE1 = ('Arial', 24, 'bold')
    POLICE2 = ('Arial', 50, 'bold')

    NIVEAUX = [[
        "XXXXXXXXXXXXXXXXXXXXXXXXX",
        "XJ X      X             X",
        "X  X XXX  X    XXXXXXX  X",
        "X  X  TX  X          X  X",
        "X  XXXXX  X  X XXXXXXX  X",
        "XT          X  X        X",
        "XXXXXXXX    X  XT X X   X",
        "X X    X XXXXXXXXXXXXXX X",
        "X X X  X X            X X",
        "X X XT X   X X   X    XTX",
        "X X XXXX X X XXXXXX X XXX",
        "X X    X X X TX     X   X",
        "X XXX XX   XXXXXXXXXXXXXX",
        "X        X X            X",
        "XXXXXXXX   XTX  X X XXX X",
        "X      X X XXX  X X XT  X",
        "X  XXX X X      X X XXXXX",
        "X XXT  X X  XXXXXXX X X X",
        "X  XXXXX X              X",
        "X          XXXXXXXXXX X X",
        "XXXXX  XXXXX            X",
        "X          X X X XX XXXXX",
        "X XXXXXXXX X XXX  X    XX",
        "X     TX   X  XT X   X  X",
        "XXXXXXXXXXXXXXXXXXXXXXXXX"]]

    #fn.tracer(False)  # On enleve les mises a jour de l'ecran.

    stylo = Stylo()
    joueur = Joueur()

    tresors = []
    murs = []
    setup_labyrinthe(NIVEAUX[0])

    def setup_labyrinthe(niveau):
        for y in range(len(niveau)):
            for x in range(len(niveau[y])):
                caractere = niveau[y][x]
                ecran_x = -288 + (x * 24)
                ecran_y = 288 - (y * 24)

                if caractere == "X":
                    stylo.goto(ecran_x, ecran_y)
                    stylo.stamp()
                    murs.append((ecran_x, ecran_y))
                elif caractere == "J":
                    joueur.goto(ecran_x, ecran_y)
                elif caractere == "T":
                    tresors.append(Tresor(ecran_x, ecran_y))

    def scorefn():
        global score

        for tresor in tresors:
            if joueur.collision(tresor):
                tresor.destruction()
                tresors.remove(tresor)
                score += 100
                marker.undo()
                marker.write(score, font=POLICE1)

                if score == 1000 :
                    marker.goto(-150, 0)
                    marker.write("You Win !", font=POLICE2)

    fn.onkeypress(joueur.gauche, "Left")
    fn.onkeypress(joueur.droite, "Right")
    fn.onkeypress(joueur.haut, "Up")
    fn.onkeypress(joueur.bas, "Down")
    fn.onkey(fn.bye, "Escape")
    fn.listen()

    score = 0

    marker = Turtle(visible=False)
    marker.penup()
    marker.color('gray')
    marker.goto(-275, 305)
    marker.write("No Escape !", font=POLICE1)
    marker.goto(240, 305)
    marker.write(score, font=POLICE1)

    fn.tracer(True)  # On remet les mises a jour de l'ecran

    fn.mainloop()

if a==0:
    boucle=False
从海龟导入海龟,屏幕
柱花类(海龟):
定义初始化(自):
乌龟.uuuu init_uuuuuuuu(self,“mur.gif”)
自身颜色(“白色”)
self.penup()
自身速度(“最快”)
乌龟类:
定义初始化(自):
乌龟.uuuu init_uuuuuu(self,“face.gif”)
自我颜色(“蓝色”)
self.penup()
自身速度(“最快”)
def haut(self):
将_移动到_x=self.xcor()
将_移动到_y=self.ycor()+24
self.shape(“back.gif”)
如果(移动到x,移动到y)不在MUR中:
self.goto(移动到x,移动到y)
分数fn()
def bas(自身):
将_移动到_x=self.xcor()
将_移动到_y=self.ycor()-24
self.shape(“face.gif”)
如果(移动到x,移动到y)不在MUR中:
self.goto(移动到x,移动到y)
分数fn()
def gauche(自我):
将_移动到_x=self.xcor()-24
将_移动到_y=self.ycor()
self.shape(“left.gif”)
如果(移动到x,移动到y)不在MUR中:
self.goto(移动到x,移动到y)
分数fn()
def droite(自):
将_移动到_x=self.xcor()+24
将_移动到_y=self.ycor()
self.shape(“right.gif”)
如果(移动到x,移动到y)不在MUR中:
self.goto(移动到x,移动到y)
分数fn()
def碰撞(自身、其他):
返回自我距离(其他)<5
三级甲鱼(海龟):
定义初始化(self,x,y):
乌龟.uuuu init_uuuuuuuuu(self,“tresor.gif”)
self.penup()
自身速度(“最快”)
self.goto(x,y)
def销毁(自我):
self.hideturtle()
self.goto(20002000)
类Forme(对象):
定义初始(自身、长度、宽度、颜色、侧面):
self.length=长度
self.width=宽度
self.color=颜色
self.sides=sides
def牵引(自):
t=海龟。钢笔()
布克尔=真
while boucle:#boucle菜单
a=int(输入(“选择图表aéaliser avec海龟:\n1.Jouer\n2.leadboard\n0.Sortir”))
如果a==1:
fn=屏幕()
fn.bgcolor(“黑色”)
fn.标题(“无逃脱!”)
fn.设置(700700)
IMAGES=[“right.gif”、“left.gif”、“face.gif”、“back.gif”、“tresor.gif”、“mur.gif”、“sol.gif”]
对于图像中的图像:
#在一条路的影像上,是一条诺特尔迷宫。
fn.addshape(图像)
policy1=('Arial',24',bold')
POLICE2=('Arial',50',bold')
NIVEAUX=[[
“XXXXXXXXXXXXXXXXXXXXX”,
“XJ X X”,
“X X XXX X XXXXXXX X”,
“X X X X X X X”,
“X XXXXX X XXXXXX X”,
“XT X X”,
“XXXXXXXXX XT X X X”,
“X X xxxxxxxxx X”,
“X X X X X X”,
“X X XT X X X X XTX”,
“X X xxxxx X xxxxx X XXX”,
“X X X X X X X X X X”,
“X XXX XX XXXXXXXXXXXXX”,
“X X X”,
“XXXXXXXX XTX X XXX X”,
“X X XXX X XT X”,
“X XXX X XXXXX”,
“X XXT X XXXXXXX X X X”,
“X XXXXX X”,
“X xxxxxxxxx X X”,
“XXXXX XXXXX”,
“X X XX XXXXX”,
“X xxxxxxxxx XXX X XX”,
“X X X X X X X”,
“XXXXXXXXXXXXXXXXXXXXXX”]]
#fn.tracer(假)#关于《伊莱夫·莱斯米塞斯月刊》。
stylo=stylo()
焦耳=焦耳()
tresors=[]
murs=[]
设置迷宫(NIVEAUX[0])
def设置_迷宫(niveau):
对于范围内的y(len(niveau)):
对于范围内的x(len(niveau[y]):
caractere=niveau[y][x]
ecran_x=-288+(x*24)
ecran_y=288-(y*24)
如果字符E==“X”:
stylo.goto(本色x,本色y)
stylo.邮票()
murs.append((本色x,本色y))
elif字符==“J”:
后藤(ecran_x,ecran_y)
elif字符==“T”:
tresors.append(Tresor(ecran_x,ecran_y))
def scorefn():
全球得分
对于tresor中的tresor:
如果发生碰撞(tresor):
tresor.销毁()
tresor.移除(tresor)
分数+=100
marker.undo()
marker.write(分数,字体=1)
如果分数=1000:
marker.goto(-150,0)
marker.write(“你赢了!”,font=POLICE2)
fn.onkeypress(Jouer.gauche,“左”)
fn.onkeypress(jouer.droite,“右”)
fn.onkeypress(jouer.haut,“向上”)
fn.onkeypress(jouer.bas,“向下”)
fn.onkey(fn.bye,“逃脱”)
听
分数=0
标记=海龟(可见=假)
marker.penup()
marker.color('gray'))
标记。转到(-275305)
marker.write(“无转义!”,font=policy1)
marker.goto(240305)
marker.write(分数,字体=1)
fn.tracer(真)#关于《米塞斯日报》
fn.mainloop()
如果a==0:
boucle=False
有人能告诉我为什么我会这样吗
boucle = True

while boucle:  # Boucle menu
    a = int(input("Choisissez la figure à réaliser avec Turtle :\n1. Jouer \n2. Leaderboard \n0. Sortir"))

    if a == 1:
        fn = Screen()
        ...
        fn.mainloop()

    if a == 2:
        pass  # implement leaderboard

    if a == 0:
        boucle = False
Turtle.__init__(self, "mur.gif")
super().__init__("mur.gif")
move_to_x = self.xcor()
move_to_y = self.ycor() + 24
if (move_to_x, move_to_y) not in murs:
    ...
from turtle import Turtle, Screen

POLICE1 = ('Arial', 24, 'bold')
POLICE2 = ('Arial', 50, 'bold')

NIVEAUX = [[
    "XXXXXXXXXXXXXXXXXXXXXXXXX",
    "XJ X      X             X",
    "X  X XXX  X    XXXXXXX  X",
    "X  X  TX  X          X  X",
    "X  XXXXX  X  X XXXXXXX  X",
    "XT          X  X        X",
    "XXXXXXXX    X  XT X X   X",
    "X X    X XXXXXXXXXXXXXX X",
    "X X X  X X            X X",
    "X X XT X   X X   X    XTX",
    "X X XXXX X X XXXXXX X XXX",
    "X X    X X X TX     X   X",
    "X XXX XX   XXXXXXXXXXXXXX",
    "X        X X            X",
    "XXXXXXXX   XTX  X X XXX X",
    "X      X X XXX  X X XT  X",
    "X  XXX X X      X X XXXXX",
    "X XXT  X X  XXXXXXX X X X",
    "X  XXXXX X              X",
    "X          XXXXXXXXXX X X",
    "XXXXX  XXXXX            X",
    "X          X X X XX XXXXX",
    "X XXXXXXXX X XXX  X    XX",
    "X     TX   X  XT X   X  X",
    "XXXXXXXXXXXXXXXXXXXXXXXXX"]]

class Stylo(Turtle):
    def __init__(self):
        super().__init__("square")
        self.speed('fastest')
        self.color("white")
        self.penup()

class Joueur(Turtle):
    def __init__(self):
        super().__init__("turtle")
        self.speed('fastest')
        self.color("green")
        self.penup()

    def haut(self):
        self.setheading(90)

        x, y = self.position()
        move_to = (int(x), int(y) + 24)

        if move_to not in murs:
            self.goto(move_to)

        scorefn()

    def bas(self):
        self.setheading(270)

        x, y = self.position()
        move_to = (int(x), int(y) - 24)

        if move_to not in murs:
            self.goto(move_to)

        scorefn()

    def gauche(self):
        self.setheading(180)

        x, y = self.position()
        move_to = (int(x) - 24, int(y))

        if move_to not in murs:
            self.goto(move_to)

        scorefn()

    def droite(self):
        self.setheading(0)

        x, y = self.position()
        move_to = (int(x) + 24, int(y))

        if move_to not in murs:
            self.goto(move_to)

        scorefn()

    def collision(self, other):
        return self.distance(other) < 5

class Tresor(Turtle):
    def __init__(self, position):
        super().__init__("triangle")
        self.setheading(90)  # make look like pile of gold
        self.color("gold")
        self.penup()
        self.goto(position)
        tresors.append(self)

    def destruction(self):
        tresors.remove(self)
        self.hideturtle()

def setup_labyrinthe(niveau):

    screen.tracer(False)

    for y in range(len(niveau)):
        for x in range(len(niveau[y])):
            caractere = niveau[y][x]
            ecran = ((x * 24) - 288, 288 - (y * 24))

            if caractere == "X":
                stylo.goto(ecran)
                stylo.stamp()
                murs.append(ecran)
            elif caractere == "J":
                joueur.goto(ecran)
            elif caractere == "T":
                Tresor(ecran)

    screen.tracer(True)

def scorefn():
    global score

    for tresor in tresors:
        if joueur.collision(tresor):
            tresor.destruction()

            score += 100
            marker.undo()
            marker.write(score, font=POLICE1)

            if score >= 1000:
                marker.goto(-150, 0)
                marker.color('red')
                marker.write("You Win!", font=POLICE2)

                # disable movements but leave Escape/exit active
                for direction in ["Left", "Right", "Up", "Down"]:
                    screen.onkeypress(None, direction)

screen = Screen()
screen.bgcolor("black")
screen.title("No Escape!")
screen.setup(700, 700)

tresors = []
murs = []

stylo = Stylo()
joueur = Joueur()

setup_labyrinthe(NIVEAUX[0])

score = 0

marker = Turtle(visible=False)
marker.penup()
marker.color('gray')
marker.goto(-275, 305)
marker.write("No Escape!", font=POLICE1)
marker.goto(240, 305)
marker.write(score, font=POLICE1)

screen.onkeypress(joueur.gauche, "Left")
screen.onkeypress(joueur.droite, "Right")
screen.onkeypress(joueur.haut, "Up")
screen.onkeypress(joueur.bas, "Down")
screen.onkey(screen.bye, "Escape")
screen.listen()

screen.mainloop()