-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPRO.py
More file actions
171 lines (134 loc) · 5.49 KB
/
Copy pathPRO.py
File metadata and controls
171 lines (134 loc) · 5.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
import tkinter as tk
from tkinter import ttk, filedialog, messagebox
from pymongo import MongoClient
import gridfs
from PIL import Image, ImageTk
client = MongoClient("mongodb://localhost:27017/")
db = client["college_db"]
collection = db["students"]
fs = gridfs.GridFS(db)
root = tk.Tk()
root.title("Student Management System")
root.geometry("820x560")
root.configure(bg="#eef2f7")
root.resizable(False, False)
photo_path = None
style = ttk.Style()
style.theme_use("clam")
style.configure("TFrame", background="#eef2f7")
style.configure("Card.TFrame", background="white", relief="raised")
style.configure("TLabel", background="white", font=("Segoe UI", 10))
style.configure("Header.TLabel", background="#1f2937", foreground="white", font=("Segoe UI", 16, "bold"))
style.configure("TButton", font=("Segoe UI", 10), padding=8)
style.map("TButton", background=[("active", "#2563eb")])
def choose_photo():
global photo_path
photo_path = filedialog.askopenfilename(filetypes=[("Image Files", "*.jpg *.png *.jpeg")])
if photo_path:
img = Image.open(photo_path).resize((150, 150))
photo = ImageTk.PhotoImage(img)
photo_label.config(image=photo)
photo_label.image = photo
def save_student():
data = {
"prn": entry_prn.get(),
"name": entry_name.get(),
"course": combo_course.get(),
"year": combo_year.get(),
"division": combo_div.get(),
"mobile": entry_mobile.get(),
"email": entry_email.get()
}
if "" in data.values() or not photo_path:
messagebox.showerror("Error", "Please fill all fields")
return
with open(photo_path, "rb") as f:
photo_id = fs.put(f, filename=data["prn"])
data["photo_id"] = photo_id
collection.insert_one(data)
messagebox.showinfo("Success", "Student saved successfully")
clear_fields()
def retrieve_student():
prn = entry_prn.get()
student = collection.find_one({"prn": prn})
if not student:
messagebox.showerror("Error", "Student not found")
return
entry_name.delete(0, tk.END)
entry_mobile.delete(0, tk.END)
entry_email.delete(0, tk.END)
entry_name.insert(0, student["name"])
entry_mobile.insert(0, student["mobile"])
entry_email.insert(0, student["email"])
combo_course.set(student["course"])
combo_year.set(student["year"])
combo_div.set(student["division"])
img_data = fs.get(student["photo_id"]).read()
with open("temp.jpg", "wb") as f:
f.write(img_data)
img = Image.open("temp.jpg").resize((150, 150))
photo = ImageTk.PhotoImage(img)
photo_label.config(image=photo)
photo_label.image = photo
def clear_fields():
for e in [entry_prn, entry_name, entry_mobile, entry_email]:
e.delete(0, tk.END)
combo_course.set("")
combo_year.set("")
combo_div.set("")
photo_label.config(image="")
header = ttk.Label(root, text=" Student Management System", style="Header.TLabel", anchor="w")
header.pack(fill="x", ipady=10)
content = ttk.Frame(root, padding=20)
content.pack(fill="both", expand=True)
card_form = ttk.Frame(content, style="Card.TFrame", padding=20)
card_form.grid(row=0, column=0, padx=10, pady=10, sticky="n")
fields = [
("PRN", None),
("Full Name", None),
("Course", None),
("Year", None),
("Division", None),
("Mobile", None),
("Email", None)
]
label_prn = ttk.Label(card_form, text="PRN")
label_prn.grid(row=0, column=0, sticky="w", pady=6)
entry_prn = ttk.Entry(card_form, width=28)
entry_prn.grid(row=0, column=1, pady=6)
label_name = ttk.Label(card_form, text="Full Name")
label_name.grid(row=1, column=0, sticky="w", pady=6)
entry_name = ttk.Entry(card_form, width=28)
entry_name.grid(row=1, column=1, pady=6)
label_course = ttk.Label(card_form, text="Course")
label_course.grid(row=2, column=0, sticky="w", pady=6)
combo_course = ttk.Combobox(card_form, values=["BCA", "MCA", "BSc", "MSc"], width=26, state="readonly")
combo_course.grid(row=2, column=1, pady=6)
label_year = ttk.Label(card_form, text="Year")
label_year.grid(row=3, column=0, sticky="w", pady=6)
combo_year = ttk.Combobox(card_form, values=["FY", "SY", "TY"], width=26, state="readonly")
combo_year.grid(row=3, column=1, pady=6)
label_div = ttk.Label(card_form, text="Division")
label_div.grid(row=4, column=0, sticky="w", pady=6)
combo_div = ttk.Combobox(card_form, values=["A", "B", "C"], width=26, state="readonly")
combo_div.grid(row=4, column=1, pady=6)
label_mobile = ttk.Label(card_form, text="Mobile")
label_mobile.grid(row=5, column=0, sticky="w", pady=6)
entry_mobile = ttk.Entry(card_form, width=28)
entry_mobile.grid(row=5, column=1, pady=6)
label_email = ttk.Label(card_form, text="Email")
label_email.grid(row=6, column=0, sticky="w", pady=6)
entry_email = ttk.Entry(card_form, width=28)
entry_email.grid(row=6, column=1, pady=6)
btn_frame = ttk.Frame(card_form)
btn_frame.grid(row=7, column=0, columnspan=2, pady=15)
ttk.Button(btn_frame, text="Save", command=save_student).grid(row=0, column=0, padx=6)
ttk.Button(btn_frame, text="Retrieve", command=retrieve_student).grid(row=0, column=1, padx=6)
ttk.Button(btn_frame, text="Clear", command=clear_fields).grid(row=0, column=2, padx=6)
card_photo = ttk.Frame(content, style="Card.TFrame", padding=20)
card_photo.grid(row=0, column=1, padx=10, pady=10, sticky="n")
ttk.Label(card_photo, text="Student Photo", font=("Segoe UI", 11, "bold")).pack(pady=5)
photo_label = ttk.Label(card_photo)
photo_label.pack(pady=10)
ttk.Button(card_photo, text="Upload Photo", command=choose_photo).pack(pady=5)
root.mainloop()