Advertisement
Guest User

zMNz

a guest
Oct 21st, 2016
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 4.00 KB | None | 0 0
  1. # -*- coding: cp1252 -*-
  2. from Tkinter import *
  3. import tkMessageBox
  4.  
  5. class reconocimiento:
  6.     global ventana
  7.     global buton
  8.     global text
  9.     global label
  10.     global matriz
  11.     global texto
  12.     global pila
  13.     global ventana_hijo
  14.     global lis_pila
  15.     global coo
  16.    
  17.     def __init__(self):
  18.         #Creacion interface
  19.         self.ventana= Tk()
  20.         self.ventana.geometry("400x300")
  21.         self.ventana.title("Validacion de pila")
  22.         self.ventana.configure(background="medium sea green")
  23.         self.ventana.resizable(width=False, height=False)
  24.         self.buton = Button(self.ventana, text="Verificar", width=12, command=lambda: self.ejecutar()).place(x=180, y=100)
  25.         self.label = Label(self.ventana, text="Cadena:").place(x=60, y=70)
  26.         self.texto = StringVar()
  27.         self.text = Entry(self.ventana, width=35, textvariable=self.texto).place(x=120, y=70)
  28.  
  29.        
  30.        
  31.         ####################
  32.         #self.matriz = [range(3) for i in range(3)]
  33.         self.matriz =[["xSy","*","FDC"]]
  34.        
  35.        
  36.         self.pila =[]
  37.         self.ventana.mainloop()
  38.        
  39.        
  40.  
  41.     def ejecutar(self):
  42.         if (self.texto.get() == "v"):
  43.             tkMessageBox.showinfo("Error!", "Por favor, introdusca algo en la caja de texto...")
  44.            
  45.         else:
  46.             self.pila.append("#")
  47.             self.pila.append("S")
  48.             #self.ventana_hijo=Toplevel(self.ventana)
  49.             #self.ventana_hijo.geometry("400x300")
  50.             #self.ventana_hijo.title("Lista de la pila")
  51.             #self.lis_pila=[]
  52.             #self.lis_pila[0] = Listbox(self.ventana_hijo, width=3)
  53.             #self.lis_pila[0].place(x=0,y=0)
  54.             #self.lis_pila[0].insert(0,self.pila)
  55.             #self.lis_pila.insert()
  56.             print self.pila
  57.            
  58.            # self.coo = 10
  59.             simbolo = self.texto.get()
  60.             con =0
  61.            
  62.            
  63.             while (self.pila[len(self.pila)-1]  != "#"):
  64.                 #self.coo = self.coo + 10
  65.                 #self.lis_pila[1] = Listbox(self.ventana_hijo, width=3)
  66.                 #self.lis_pila[1].place(x=self.coo,y=0)
  67.                 #self.lis_pila[1].insert(0,self.pila)
  68.                 #Posicion de columna
  69.                
  70.                 if (self.texto.get() == ""):
  71.                     self.pila.pop()
  72.                     break    
  73.                 elif (simbolo[con] == "x"):
  74.                         simb=0
  75.                 elif (simbolo[con] == "y"):
  76.                         simb=1
  77.  
  78.                
  79.                 ##################
  80.  
  81.                 #No terminal
  82.                 if (self.pila[len(self.pila)-1] == "S"):
  83.                    
  84.                     if (self.pila[len(self.pila)-1] == "S"):
  85.                         cima=0
  86.                     if (self.matriz[cima][simb] !="*"):
  87.                         self.pila.pop()
  88.                         var =self.matriz[cima][simb]
  89.                         cadena = ""
  90.                         for i in var:
  91.                             cadena = i + cadena
  92.                         for j in cadena:
  93.                             self.pila.append(j)
  94.                     elif (self.matriz[cima][simb] =="*"):
  95.                         self.pila.pop()
  96.  
  97.                     else:
  98.                         tkMessageBox.showinfo("Error!", "Error, intente con otra cadena")
  99.                         break
  100.  
  101.                 #Terminal
  102.                 elif (self.pila[len(self.pila)-1] == "x" or self.pila[len(self.pila)-1] == "y"):
  103.                     con+=1
  104.                     self.pila.pop()
  105.                 else:
  106.                     tkMessageBox.showinfo("Error!", "Error, intente con otra cadena")
  107.                     break
  108.  
  109.                
  110.                
  111.                 print self.pila
  112.  
  113.             if  (self.pila[len(self.pila)-1] == "#"):
  114.                 tkMessageBox.showinfo("Felicidades!", "Cadena aceptada")
  115.                
  116.            
  117.              
  118. x=reconocimiento()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement