def上的语法错误

时间:2013-08-15 15:30:02

标签: python python-2.7

from Tkinter import *

class Nodo:

    def __init__(self,x,y=None):
        self.valor=x
        self.sgte=y
class Cola (Nodo):

    def __init__(self,n):
        self.capa=n
        self.prim=None
        self.ulti=None
    def Vacio(self):
        if self.prim==None:
            return True
        return False 
    def Lleno(self):
        a=self.prim
        b=0
        while a!=None:
            a=a.sgte
            b=b+1
        if b==self.capa: return True
        else: return False
    def Existe (self,x):
        a=self.prim
        while a!= None:
            if a.valor== x:
                return True
            a=a.sgte
        return False 
    def poner (self,x):
        nodo=Nodo(x,None)
        if x.isalpha()==True or x.isdigit()==True:
            if self.Lleno() == True:
                raise ColaLlena()
            if self.Existe()==True:
                raise YaExiste()
            if self.Vacio() ==True:
                self.prim=nodo
                self.ulti=nodo
            if self.Vacio()==False:
                self.ulti.sgte=nodo
    def sacar (self,x):
        if self.Empty()==True:
            raise ColaVacia()
        a=self.prim.valor
        if self.prim.sgte !=None:
            self.prim=self.prim.sgte
        return a

    def Str(self,x):
        if self.Vacio()==True:
            return ""
        else:
            a=self.prim
            L=[]
            while a!=None:
                L.append(a.valor)
                a=a.sgte
            l=""
            for i in L:
                i=str(i)
                l=l+" "+i
            return l

class ColaLlena (Exception):

    def __init__(self):
        pass
class YaExiste (Exception):

    def __init__(self):
        pass
class ColaVacia (Exception):

    def __init__(self):
        pass


c1=Cola(10)

c2=Cola(20)

def atender1():

    if c1.Empty()== True:
        r1.delete(0,END)
        r1.insert(0,"Cola Vacia")
    else:
        a=c1.sacar()
        r1.config(text=("Atendiendo a:"+Str(a))

def atender2():

    if c2.Empty() == True:
        r2.delete(0,END)
        r2.insert(0,"Cola Vacia")
    else:
        a=c2.sacar()
        r2.config(text=("Atendiendo a:"+Str(a))

我在def atender (x)中有一个语法错误,特别是在def,我不知道为什么,我检查了所有代码,我仍然找不到问题,请帮助:c

1 个答案:

答案 0 :(得分:5)

之前的行缺少右括号:

r1.config(text=("Atendiendo a:"+Str(a))
#    ----^   --^                ---^ ^^

您有3个左括号,但仅关闭2.可以删除第二个左括号:

r1.config(text="Atendiendo a:" + Str(a))

你有几行同样的问题:

r2.config(text=("Atendiendo a:"+Str(a))
#    ----^   --^                ---^ ^^