python programmer

python programmer

Share

Coding is life

Photos from python programmer's post 17/05/2026

"zikr counter application advance application "

Photos from python programmer's post 25/12/2025

student managment system using python tkinter

17/12/2025

Learn python with us 💻💻💻

Photos from python programmer's post 04/12/2025

Learn Data structure in python from Bsic with GUI
'''- Push
- Pop
- Peek
- *Clear Stack*
- *Show Stack Sizepython'''

import tkinter as tk
from tkinter import messagebox

stack = []

def push():
val = entry.get()
if val:
stack.append(val)
entry.delete(0, tk.END)
update_display()
else:
messagebox.showwarning("Input needed", "Please enter a value")

def pop_item():
if stack:
popped = stack.pop()
messagebox.showinfo("Popped", f"Removed: {popped}")
update_display()
else:
messagebox.showwarning("Empty Stack", "Nothing to pop")

def peek():
if stack:
top = stack[-1]
messagebox.showinfo("Top Item", f"Top: {top}")
else:
messagebox.showinfo("Empty Stack", "Stack is empty")

def clear_stack():
stack.clear()
update_display()
messagebox.showinfo("Cleared", "Stack has been cleared")

def update_display():
stack_display = " -> ".join(stack) if stack else "Stack is empty"
display_label.config(text=stack_display)
size_label.config(text=f"Size: {len(stack)}")

setup
root = tk.Tk()
root.title("Stack App with Tkinter")
root.geometry("400x350")

tk.Label(root, text="Enter value to push:").pack(pady=5)
entry = tk.Entry(root)
entry.pack(pady=5)

tk.Button(root, text="Push", width=15, command=push).pack(pady=5)
tk.Button(root, text="Pop", width=15, command=pop_item).pack(pady=5)
tk.Button(root, text="Peek (Top)", width=15, command=peek).pack(pady=5)
tk.Button(root, text="Clear Stack", width=15, command=clear_stack).pack(pady=5)

display_label = tk.Label(root, text="Stack is empty", bg="orange",fg="white", width=40, height=10)
display_label.pack(pady=10)

size_label = tk.Label(root, text="Size: 0")
size_label.pack()

root.mainloop()

Category

Telephone

Address


Peshawer
Peshawar
25000

Alerts

Be the first to know and let us send you an email when python programmer posts news and promotions. Your email address will not be used for any other purpose, and you can unsubscribe at any time.

Subscribe

We will notify you when anything happens in Peshawar.