Skip to content

Commit ba0ad8e

Browse files
author
Chloe White
committed
tkinter gui for student management
1 parent d10914f commit ba0ad8e

File tree

2 files changed

+153
-0
lines changed

2 files changed

+153
-0
lines changed

student_management/app.py

Lines changed: 153 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,153 @@
1+
import tkinter as tk
2+
from tkinter import messagebox, simpledialog
3+
import pandas as pd
4+
import os
5+
6+
# ==============================
7+
# Hardcoded admin credentials
8+
# ==============================
9+
USERNAME = "admin"
10+
PASSWORD = "password123"
11+
12+
# File to store student data
13+
DATA_FILE = "students.csv"
14+
15+
# Ensure CSV exists
16+
if not os.path.exists(DATA_FILE):
17+
df = pd.DataFrame(columns=["Roll No", "Name", "Address", "DOB"])
18+
df.to_csv(DATA_FILE, index=False)
19+
20+
# ==============================
21+
# Helper functions
22+
# ==============================
23+
def get_students():
24+
return pd.read_csv(DATA_FILE)
25+
26+
def save_students(df):
27+
df.to_csv(DATA_FILE, index=False)
28+
29+
def generate_roll_no():
30+
df = get_students()
31+
if df.empty:
32+
return 1
33+
else:
34+
return df["Roll No"].max() + 1
35+
36+
# ==============================
37+
# Student operations
38+
# ==============================
39+
def add_student():
40+
name = simpledialog.askstring("Input", "Enter student name:")
41+
address = simpledialog.askstring("Input", "Enter student address:")
42+
dob = simpledialog.askstring("Input", "Enter student DOB (YYYY-MM-DD):")
43+
44+
if name and address and dob:
45+
roll_no = generate_roll_no()
46+
df = get_students()
47+
df.loc[len(df)] = [roll_no, name, address, dob]
48+
save_students(df)
49+
messagebox.showinfo("Success", f"Student {name} added with Roll No {roll_no}")
50+
else:
51+
messagebox.showwarning("Input Error", "All fields are required!")
52+
53+
def update_student():
54+
roll_no = simpledialog.askinteger("Input", "Enter roll number to update:")
55+
df = get_students()
56+
57+
if roll_no in df["Roll No"].values:
58+
name = simpledialog.askstring("Input", "Enter new name (leave blank to keep same):")
59+
address = simpledialog.askstring("Input", "Enter new address (leave blank to keep same):")
60+
dob = simpledialog.askstring("Input", "Enter new DOB (leave blank to keep same):")
61+
62+
idx = df.index[df["Roll No"] == roll_no][0]
63+
64+
if name:
65+
df.at[idx, "Name"] = name
66+
if address:
67+
df.at[idx, "Address"] = address
68+
if dob:
69+
df.at[idx, "DOB"] = dob
70+
71+
save_students(df)
72+
messagebox.showinfo("Success", f"Student with Roll No {roll_no} updated!")
73+
else:
74+
messagebox.showerror("Error", "Roll number not found!")
75+
76+
def delete_student():
77+
roll_no = simpledialog.askinteger("Input", "Enter roll number to delete:")
78+
df = get_students()
79+
80+
if roll_no in df["Roll No"].values:
81+
df = df[df["Roll No"] != roll_no]
82+
save_students(df)
83+
messagebox.showinfo("Deleted", f"Student with Roll No {roll_no} deleted!")
84+
else:
85+
messagebox.showerror("Error", "Roll number not found!")
86+
87+
def search_student():
88+
choice = simpledialog.askstring("Search", "Search by 'roll' or 'name'?").lower()
89+
df = get_students()
90+
91+
if choice == "roll":
92+
roll_no = simpledialog.askinteger("Input", "Enter roll number:")
93+
result = df[df["Roll No"] == roll_no]
94+
elif choice == "name":
95+
name = simpledialog.askstring("Input", "Enter name:")
96+
result = df[df["Name"].str.contains(name, case=False, na=False)]
97+
else:
98+
messagebox.showerror("Error", "Invalid choice!")
99+
return
100+
101+
if not result.empty:
102+
messagebox.showinfo("Result", result.to_string(index=False))
103+
else:
104+
messagebox.showinfo("Result", "No matching student found.")
105+
106+
# ==============================
107+
# Login + Dashboard
108+
# ==============================
109+
def login():
110+
entered_username = username_entry.get()
111+
entered_password = password_entry.get()
112+
113+
if entered_username == USERNAME and entered_password == PASSWORD:
114+
messagebox.showinfo("Login Success", "Welcome, Admin!")
115+
root.destroy()
116+
open_dashboard()
117+
else:
118+
messagebox.showerror("Login Failed", "Invalid username or password")
119+
120+
def open_dashboard():
121+
dashboard = tk.Tk()
122+
dashboard.title("Student Management System")
123+
dashboard.geometry("400x400")
124+
125+
tk.Label(dashboard, text="Student Management System",
126+
font=("Arial", 14, "bold")).pack(pady=15)
127+
128+
tk.Button(dashboard, text="Add Student", command=add_student, width=25).pack(pady=5)
129+
tk.Button(dashboard, text="Update Student", command=update_student, width=25).pack(pady=5)
130+
tk.Button(dashboard, text="Delete Student", command=delete_student, width=25).pack(pady=5)
131+
tk.Button(dashboard, text="Search Student", command=search_student, width=25).pack(pady=5)
132+
tk.Button(dashboard, text="Exit", command=dashboard.quit, width=25).pack(pady=10)
133+
134+
dashboard.mainloop()
135+
136+
# ==============================
137+
# Main Login Window
138+
# ==============================
139+
root = tk.Tk()
140+
root.title("Admin Login")
141+
root.geometry("300x200")
142+
143+
tk.Label(root, text="Username:").pack(pady=5)
144+
username_entry = tk.Entry(root)
145+
username_entry.pack(pady=5)
146+
147+
tk.Label(root, text="Password:").pack(pady=5)
148+
password_entry = tk.Entry(root, show="*")
149+
password_entry.pack(pady=5)
150+
151+
tk.Button(root, text="Login", command=login).pack(pady=20)
152+
153+
root.mainloop()

student_management/students.csv

Whitespace-only changes.

0 commit comments

Comments
 (0)