Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # -*- coding: cp1252 -*-
- from Tkinter import *
- import tkMessageBox
- class reconocimiento:
- global ventana
- global buton
- global text
- global label
- global matriz
- global texto
- global pila
- global ventana_hijo
- global lis_pila
- global coo
- def __init__(self):
- #Creacion interface
- self.ventana= Tk()
- self.ventana.geometry("400x300")
- self.ventana.title("Validacion de pila")
- self.ventana.configure(background="medium sea green")
- self.ventana.resizable(width=False, height=False)
- self.buton = Button(self.ventana, text="Verificar", width=12, command=lambda: self.ejecutar()).place(x=180, y=100)
- self.label = Label(self.ventana, text="Cadena:").place(x=60, y=70)
- self.texto = StringVar()
- self.text = Entry(self.ventana, width=35, textvariable=self.texto).place(x=120, y=70)
- ####################
- #self.matriz = [range(3) for i in range(3)]
- self.matriz =[["xSy","*","FDC"]]
- self.pila =[]
- self.ventana.mainloop()
- def ejecutar(self):
- if (self.texto.get() == "v"):
- tkMessageBox.showinfo("Error!", "Por favor, introdusca algo en la caja de texto...")
- else:
- self.pila.append("#")
- self.pila.append("S")
- #self.ventana_hijo=Toplevel(self.ventana)
- #self.ventana_hijo.geometry("400x300")
- #self.ventana_hijo.title("Lista de la pila")
- #self.lis_pila=[]
- #self.lis_pila[0] = Listbox(self.ventana_hijo, width=3)
- #self.lis_pila[0].place(x=0,y=0)
- #self.lis_pila[0].insert(0,self.pila)
- #self.lis_pila.insert()
- print self.pila
- # self.coo = 10
- simbolo = self.texto.get()
- con =0
- while (self.pila[len(self.pila)-1] != "#"):
- #self.coo = self.coo + 10
- #self.lis_pila[1] = Listbox(self.ventana_hijo, width=3)
- #self.lis_pila[1].place(x=self.coo,y=0)
- #self.lis_pila[1].insert(0,self.pila)
- #Posicion de columna
- if (self.texto.get() == ""):
- self.pila.pop()
- break
- elif (simbolo[con] == "x"):
- simb=0
- elif (simbolo[con] == "y"):
- simb=1
- ##################
- #No terminal
- if (self.pila[len(self.pila)-1] == "S"):
- if (self.pila[len(self.pila)-1] == "S"):
- cima=0
- if (self.matriz[cima][simb] !="*"):
- self.pila.pop()
- var =self.matriz[cima][simb]
- cadena = ""
- for i in var:
- cadena = i + cadena
- for j in cadena:
- self.pila.append(j)
- elif (self.matriz[cima][simb] =="*"):
- self.pila.pop()
- else:
- tkMessageBox.showinfo("Error!", "Error, intente con otra cadena")
- break
- #Terminal
- elif (self.pila[len(self.pila)-1] == "x" or self.pila[len(self.pila)-1] == "y"):
- con+=1
- self.pila.pop()
- else:
- tkMessageBox.showinfo("Error!", "Error, intente con otra cadena")
- break
- print self.pila
- if (self.pila[len(self.pila)-1] == "#"):
- tkMessageBox.showinfo("Felicidades!", "Cadena aceptada")
- x=reconocimiento()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement