Skip to content

Instantly share code, notes, and snippets.

@isturiz
Last active December 20, 2022 09:13
Show Gist options
  • Save isturiz/19de61921c6fbc695e6854138ed30c06 to your computer and use it in GitHub Desktop.
Save isturiz/19de61921c6fbc695e6854138ed30c06 to your computer and use it in GitHub Desktop.
Colas FIFO/LIFO
import tkinter as tk
import tkinter.font as tkFont
class Queue:
def __init__(self):
self.items = []
def is_empty(self):
return not self.items
def put(self, item):
self.items.append(item)
def getFIFO(self):
return self.items.pop(0)
def getLIFO(self):
return self.items.pop()
# Crear la ventana principal
window = tk.Tk()
window.title("COLAS FIFO / LIFO")
window.geometry("490x200")
# Crear la cola FIFO
FIFO = Queue()
labelFIFO=tk.Label(window)
ft = tkFont.Font(size=10)
labelFIFO["font"] = ft
labelFIFO["fg"] = "#000000"
labelFIFO["justify"] = "center"
labelFIFO["text"] = "COLA FIFO"
labelFIFO.place(x=85,y=0,width=70,height=25)
# Crear las etiquetas y campos de entrada para agregar elementos a la cola
labelinputFIFO = tk.Label()
ft = tkFont.Font(size=10)
labelinputFIFO["font"] = ft
labelinputFIFO["fg"] = "#000000"
labelinputFIFO["justify"] = "center"
labelinputFIFO["text"] = "Elemento a agregar:"
labelinputFIFO.place(x=10,y=40,width=124,height=30)
inputFIFO = tk.Entry()
inputFIFO["borderwidth"] = "1px"
ft = tkFont.Font(size=10)
inputFIFO["font"] = ft
inputFIFO["fg"] = "#000000"
inputFIFO["justify"] = "center"
inputFIFO["text"] = ""
inputFIFO.place(x=140,y=40,width=70,height=25)
# Crear el botón para agregar elementos a la cola
def add_to_queue():
item = inputFIFO.get()
FIFO.put(item)
inputFIFO.delete(0, 'end')
listItemsFIFO_.set(FIFO.items)
# Botón añadir FIFO
addFIFO = tk.Button(command=add_to_queue)
addFIFO["bg"] = "#f0f0f0"
ft = tkFont.Font(size=10)
addFIFO["font"] = ft
addFIFO["fg"] = "#000000"
addFIFO["justify"] = "center"
addFIFO["text"] = "Agregar"
addFIFO.place(x=140,y=70,width=70,height=25)
# Crear la etiqueta y el campo de salida para mostrar el elemento eliminado de la cola
labelOutputFIFO=tk.Label()
ft = tkFont.Font(size=10)
labelOutputFIFO["font"] = ft
labelOutputFIFO["fg"] = "#000000"
labelOutputFIFO["justify"] = "center"
labelOutputFIFO["text"] = "Elemento eliminado:"
labelOutputFIFO.place(x=10,y=120,width=118,height=30)
outputFIFO = tk.StringVar()
outputFIFO.set("")
label3 = tk.Label(textvariable=outputFIFO)
ft = tkFont.Font(size=10)
label3["font"] = ft
label3["fg"] = "#333333"
label3["justify"] = "center"
label3["text"] = ""
label3.place(x=135,y=120,width=80,height=25)
listItemsFIFO_ = tk.StringVar()
listItemsFIFO_.set("")
listItemsFIFO = tk.Label(textvariable=listItemsFIFO_)
ft = tkFont.Font(size=10)
listItemsFIFO["font"] = ft
listItemsFIFO["fg"] = "#333333"
listItemsFIFO["justify"] = "center"
listItemsFIFO["text"] = ""
listItemsFIFO.place(x=135,y=100,width=80,height=25)
# Crear el botón para eliminar elementos de la cola
def remove_from_queue_FIFO():
if FIFO.is_empty():
outputFIFO.set("Cola vacía")
else:
item = FIFO.getFIFO()
outputFIFO.set(item)
listItemsFIFO_.set(FIFO.items)
# Botón de eliminar cola FIFO
deleteFIFO = tk.Button(command=remove_from_queue_FIFO)
deleteFIFO["bg"] = "#f0f0f0"
ft = tkFont.Font(size=10)
deleteFIFO["font"] = ft
deleteFIFO["fg"] = "#000000"
deleteFIFO["justify"] = "center"
deleteFIFO["text"] = "Eliminar"
deleteFIFO.place(x=140,y=150,width=70,height=25)
# Crear la cola LIFO
LIFO = Queue()
labelLIFO=tk.Label(window)
ft = tkFont.Font(size=10)
labelLIFO["font"] = ft
labelLIFO["fg"] = "#000000"
labelLIFO["justify"] = "center"
labelLIFO["text"] = "COLA LIFO"
labelLIFO.place(x=335,y=0,width=70,height=25)
# Crear las etiquetas y campos de entrada para agregar elementos a la cola
labelinputLIFO = tk.Label()
ft = tkFont.Font(size=10)
labelinputLIFO["font"] = ft
labelinputLIFO["fg"] = "#000000"
labelinputLIFO["justify"] = "center"
labelinputLIFO["text"] = "Elemento a agregar:"
labelinputLIFO.place(x=260,y=40,width=124,height=30)
inputLIFO = tk.Entry()
inputLIFO["borderwidth"] = "1px"
ft = tkFont.Font(size=10)
inputLIFO["font"] = ft
inputLIFO["fg"] = "#000000"
inputLIFO["justify"] = "center"
inputLIFO["text"] = ""
inputLIFO.place(x=390,y=40,width=70,height=25)
# Crear el botón para agregar elementos a la cola
def add_to_queue_LIFO():
item = inputLIFO.get()
LIFO.put(item)
inputLIFO.delete(0, 'end')
listItemsLIFO_.set(LIFO.items)
# Botón añadir FIFO
addLIFO = tk.Button(command=add_to_queue_LIFO)
addLIFO["bg"] = "#f0f0f0"
ft = tkFont.Font(size=10)
addLIFO["font"] = ft
addLIFO["fg"] = "#000000"
addLIFO["justify"] = "center"
addLIFO["text"] = "Agregar"
addLIFO.place(x=390,y=70,width=70,height=25)
# Crear la etiqueta y el campo de salida para mostrar el elemento eliminado de la cola
labelOutputLIFO=tk.Label()
ft = tkFont.Font(size=10)
labelOutputLIFO["font"] = ft
labelOutputLIFO["fg"] = "#000000"
labelOutputLIFO["justify"] = "center"
labelOutputLIFO["text"] = "Elemento eliminado:"
labelOutputLIFO.place(x=260,y=120,width=118,height=30)
outputLIFO = tk.StringVar()
outputLIFO.set("")
label4 = tk.Label(textvariable=outputLIFO)
ft = tkFont.Font(size=10)
label4["font"] = ft
label4["fg"] = "#333333"
label4["justify"] = "center"
label4["text"] = "mes"
label4.place(x=385,y=120,width=80,height=25)
listItemsLIFO_ = tk.StringVar()
listItemsLIFO_.set("")
listItemsLIFO = tk.Label(textvariable=listItemsLIFO_)
ft = tkFont.Font(size=10)
listItemsLIFO["font"] = ft
listItemsLIFO["fg"] = "#333333"
listItemsLIFO["justify"] = "center"
listItemsLIFO["text"] = ""
listItemsLIFO.place(x=385,y=100,width=80,height=25)
# Crear el botón para eliminar elementos de la cola
def remove_from_queue_LIFO():
if LIFO.is_empty():
outputLIFO.set("Cola vacía")
else:
item = LIFO.getLIFO()
outputLIFO.set(item)
listItemsLIFO_.set(LIFO.items)
# Botón de eliminar cola FIFO
deleteLIFO = tk.Button(command=remove_from_queue_LIFO)
deleteLIFO["bg"] = "#f0f0f0"
ft = tkFont.Font(size=10)
deleteLIFO["font"] = ft
deleteLIFO["fg"] = "#000000"
deleteLIFO["justify"] = "center"
deleteLIFO["text"] = "Eliminar"
deleteLIFO.place(x=390,y=150,width=70,height=25)
GLabel_419=tk.Label()
GLabel_419["bg"] = "#000000"
ft = tkFont.Font(size=10)
GLabel_419["font"] = ft
GLabel_419["fg"] = "#333333"
GLabel_419["justify"] = "center"
GLabel_419["text"] = ""
GLabel_419.place(x=240,y=0,width=5,height=200)
# Iniciar el bucle de eventos
window.mainloop()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment