π₯ Python Student Grade Calculator (GUI) – Modern & Stylish Application with Full Code
Demo :
Click Video πππ
Description:
Want to build a modern & stylish Python Student Grade Calculator with an interactive GUI? π In this post, we provide:
✅ Full Python Code for a Grade Calculator
✅ Modern GUI Design (Tkinter-based)
✅ Step-by-step guide to implement
✅ YouTube demo video for better understanding
Code :
import tkinter as tk
from tkinter import messagebox
# Function to calculate grade
def calculate_grade():
try:
marks = [float(entry.get()) for entry in entries]
total_marks = sum(marks)
percentage = (total_marks / (len(marks) * 100)) * 100
if percentage >= 90:
grade, color, msg = "A+", "#28a745", "π Excellent Performance! Keep it up!"
elif percentage >= 80:
grade, color, msg = "A", "#17a2b8", "π Great Job! You did well!"
elif percentage >= 70:
grade, color, msg = "B", "#ffc107", "π Good! But there's room for improvement."
elif percentage >= 60:
grade, color, msg = "C", "#fd7e14", "π Study harder to improve your score."
elif percentage >= 50:
grade, color, msg = "D", "#dc3545", "⚠️ Work harder! You need to improve."
else:
grade, color, msg = "F", "#6c757d", "❌ You have failed. Don't give up, try again!"
# Update result label
result_label.config(text=f"Total Marks: {total_marks} / {len(marks) * 100}\nPercentage: {percentage:.2f}%\nGrade: {grade}", fg=color)
messagebox.showinfo("Performance Summary", msg)
except ValueError:
messagebox.showerror("Input Error", "Please enter valid numeric marks!")
# GUI Setup
root = tk.Tk()
root.title("π Student Grade Calculator")
root.geometry("400x500")
root.configure(bg="#2c3e50")
# Heading
tk.Label(root, text="π Student Grade Calculator", font=("Arial", 16, "bold"), bg="#2c3e50", fg="white").pack(pady=10)
# Input Fields
entries = []
for i in range(5): # Default 5 subjects
frame = tk.Frame(root, bg="#2c3e50")
frame.pack(pady=5)
tk.Label(frame, text=f"Subject {i+1} Marks:", font=("Arial", 12), bg="#2c3e50", fg="white").pack(side=tk.LEFT)
entry = tk.Entry(frame, font=("Arial", 12), width=10)
entry.pack(side=tk.RIGHT, padx=10)
entries.append(entry)
# Calculate Button
calculate_btn = tk.Button(root, text="Calculate Grade", font=("Arial", 14, "bold"), bg="#1abc9c", fg="white", padx=20, pady=5, command=calculate_grade)
calculate_btn.pack(pady=15)
# Result Label
result_label = tk.Label(root, text="", font=("Arial", 14, "bold"), bg="#2c3e50", fg="white")
result_label.pack(pady=10)
# Run the App
root.mainloop()
Comments
Post a Comment