Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from tkinter import *
- #root.geometry('500x500')
- '''
- mainFrame = LabelFrame(root,text='first frame',padx=50)
- mainFrame.grid(padx=10,pady=10)
- '''
- #Classes
- class Stack_Gui:
- def __init__(self,top):
- global ent
- global lst
- lst=list()
- psh = Button(top,text='PUSH',width=20,bg='#4db8ff',command=self.validatePush).grid(row=0,column=1,padx=20,pady=10)
- pp = Button(top,text='POP',width=20,bg='#4db8ff',command=self.validatePop).grid(row=0,column=2,padx=20)
- pek = Button(top,text='PEAK',width=20,bg='#4db8ff',command=self.validatePeak).grid(row=0,column=3,padx=20)
- ent = Entry(top,borderwidth=5)
- ent.grid(row=2,column=1,padx=20)
- btn = Button(top,text='Clear',width=10,bg='#e5e5cc',height=2,command=self.clear)
- btn.grid(row=3,column=1)
- lab1 = Label(top,text="",bg='#ffff80',width=10,height=5)
- lab1.grid(row=2,column=2,pady=1)
- lab2 = Label(top,text="",bg='#ffff80',width=10,height=5)
- lab2.grid(row=3,column=2,pady=1)
- lab3 = Label(top,text="",width=10,bg='#ffff80',height=5)
- lab3.grid(row=4,column=2,pady=1)
- lab4 = Label(top,text="",bg='#ffff80',width=10,height=5)
- lab4.grid(row=5,column=2,pady=1)
- lab5 = Label(top,width=10,bg='#ffff80',height=5)
- lab5.grid(row=6,column=2,pady=1)
- #Exit button
- ext = Button(top,text='Exit',width=20,command=quit,bg='#ff471a').grid(row=7,column=3)
- #Top and bottom Lables
- labt = Label(top,text='<----------Top').grid(row=2,column=3)
- labb = Label(top,text='<-------Bottom').grid(row=6,column=3,padx=0)
- #Push() operation
- def Push1(self):
- if len(lst) == 0:
- #lab5.pack_forget()
- lab5 = Label(top,text=ent.get(),bg='#ff944d',width=10,height=5)
- lab5.grid(row=6,column=2,pady=1)
- lst.append(ent.get())
- elif len(lst) == 1:
- lab4 = Label(top,text=ent.get(),bg='#ff944d',width=10,height=5)
- lab4.grid(row=5,column=2,pady=1)
- lst.append(ent.get())
- elif len(lst) == 2:
- lab4 = Label(top,text=ent.get(),bg='#ff944d',width=10,height=5)
- lab4.grid(row=4,column=2,pady=1)
- lst.append(ent.get())
- elif len(lst) == 3:
- lab4 = Label(top,text=ent.get(),bg='#ff944d',width=10,height=5)
- lab4.grid(row=3,column=2,pady=1)
- lst.append(ent.get())
- else:
- lab1 = Label(top,text=ent.get(),bg='#ff944d',width=10,height=5)
- lab1.grid(row=2,column=2,pady=1)
- lst.append(ent.get())
- self.clear()
- #Pop() operation
- def Pop1(self):
- if len(lst) == 1:
- #lab5.pack_forget()
- lab5 = Label(top,text='',bg='#ffff80',width=10,height=5)
- lab5.grid(row=6,column=2,pady=1)
- lst.pop()
- elif len(lst) == 2:
- lab4 = Label(top,text='',bg='#ffff80',width=10,height=5)
- lab4.grid(row=5,column=2,pady=1)
- lst.pop()
- elif len(lst) == 3:
- lab4 = Label(top,text='',bg='#ffff80',width=10,height=5)
- lab4.grid(row=4,column=2,pady=1)
- lst.pop()
- elif len(lst) == 4:
- lab4 = Label(top,text='',bg='#ffff80',width=10,height=5)
- lab4.grid(row=3,column=2,pady=1)
- lst.pop()
- else:
- lab1 = Label(top,text='',bg='#ffff80',width=10,height=5)
- lab1.grid(row=2,column=2,pady=1)
- lst.pop()
- #Peak() operation
- def Peak1(self):
- labn = Label(top,text=lst[-1],bg='#ff944d',width=10,height=5)
- labn.grid(row=4,column=3)
- labn.after(5000 , lambda: labn.destroy())
- #Validator for push
- def validatePush(self):
- if len(lst)<5:
- if (len(ent.get())==0):
- self.InvalidInput()
- else:
- self.Push1()
- else:
- self.Full()
- #Validator for pop
- def validatePop(self):
- if len(lst)==0:
- self.Empty()
- else:
- self.Pop1()
- #Validator for peak
- def validatePeak(self):
- if len(lst)==0:
- self.Empty()
- else:
- self.Peak1()
- #Invalid Input
- def InvalidInput(self):
- full = Toplevel(bg='#8cff66')
- full.title('InvalalidInput')
- lab = Label(full,text="Enter any value.",fg='blue',bg='#8cff66',width=20,height=5)
- lab.grid(row=1,column=1)
- full.resizable(0,0)
- full.after(5000 , lambda: full.destroy())
- btn = Button(full,text='Exit',width=10,height=2,command=full.destroy)
- btn.grid(row=2,column=2)
- #Stack Full
- def Full(self):
- full = Toplevel(bg='#8cff66')
- full.title('Warning')
- lab = Label(full,text="Stack is Full",fg='blue',bg='#8cff66',width=20,height=5)
- lab.grid(row=1,column=1)
- full.resizable(0,0)
- full.after(5000 , lambda: full.destroy())
- btn = Button(full,text='Exit',width=10,height=2,command=full.destroy)
- btn.grid(row=2,column=2)
- #Stack Empty
- def Empty(self):
- ept = Toplevel(bg='#8cff66')
- ept.title("Warning")
- lab = Label(ept,text="Stack is Empyt",fg='blue',bg='#8cff66',width=20,height=5)
- lab.grid(row=1,column=1)
- ept.resizable(0,0)
- ept.after(5000 , lambda: ept.destroy())
- btn = Button(ept,text='Exit',width=10,height=2,command=ept.destroy)
- btn.grid(row=2,column=2)
- #clear Entry Field
- def clear(self):
- ent.delete(0,END)
- #if __name__ == 'main':
- root = Tk()
- #img = PhotoImage(file="hacker.jpg")
- top = Frame(root,bg='#123456')
- top.grid()
- #top.create_image(20,20, anchor=NW, image=img)
- obj = Stack_Gui(top)
- root.resizable(0,0)
- root.mainloop()
Add Comment
Please, Sign In to add comment