-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
479 lines (401 loc) · 16.6 KB
/
main.py
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
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
from tkinter import *
from datetime import date
from tkinter import filedialog
from tkinter import messagebox
from PIL import Image, ImageTk
import os
from tkinter.ttk import Combobox
import openpyxl
from openpyxl import Workbook
import pathlib
from datetime import datetime
import re
from customtkinter import *
set_default_color_theme("blue")
set_appearance_mode("light")
background = "#06283D"
framebg = "#EDEDED"
framefg = "#06283D"
undo_history = []
redo_history = []
root = CTk()
root.title("Student Registration")
root.geometry("1250x700+210+100")
root.configure(bg=background)
file = pathlib.Path('Students_data.xlsx')
if file.exists():
pass
else:
file = Workbook()
sheet = file.active
sheet['A1'] = "Registration No."
sheet['B1'] = "Name"
sheet['C1'] = "Course"
sheet['D1'] = "Gender"
sheet['E1'] = "DOB"
sheet['F1'] = "Date of Registration"
sheet['G1'] = "Religion"
sheet['H1'] = "CNIC"
sheet['I1'] = "Father's Name"
sheet['J1'] = "Mother's Name"
sheet['K1'] = "Father's Occupation"
sheet['L1'] = "Mother's Occupation"
file.save('Students_data.xlsx')
def Exit(*args):
root.destroy()
def showimage(*args):
global filename
global img
filename = filedialog.askopenfilename(initialdir=os.getcwd(),
title="Select image file", filetype=(("JPG File", "*.jpg"),
("PNG File", "*.png"),
("All Files", "*.txt")))
img = Image.open(filename)
resized_image = img.resize((190, 190))
photo2 = ImageTk.PhotoImage(resized_image)
lbl.configure(image=photo2)
lbl.image = photo2
def registration_no():
file = openpyxl.load_workbook('Students_data.xlsx')
sheet = file.active
row = sheet.max_row
max_row_value = sheet.cell(row=row, column=1).value
try:
Registration.set(max_row_value)
except:
Registration.set("1")
def clear(*args):
global undo_history
global img
Name.set('')
DOB.set('')
Religion.set('')
CNIC.set('')
Date.set(d1)
Course.set("Select Course")
F_Name.set('')
Father_Occupation.set('')
M_Name.set('')
Mother_Occupation.set('')
registration_no()
saveButton.configure(state="normal")
img1 = PhotoImage(file='Images1/upload photo.png')
lbl.configure(image=img1)
lbl.image = img1
# img = Image.open("Images1/upload photo.png")
# resized_image = img.resize((190, 190))
# photo2 = ImageTk.PhotoImage(resized_image)
# lbl.configure(image=photo2)
# lbl.image = photo2
# messagebox.showinfo("Success", "Data cleared successfully.")
def save_data(*args):
R1 = Registration.get()
N1 = Name.get()
C1 = Course.get()
try:
G1 = gender
except:
messagebox.showerror("error", "Select Gender")
D2 = DOB.get()
D1 = Date.get()
Re1 = Religion.get()
S1 = CNIC.get()
fathername = F_Name.get()
mothername = M_Name.get()
F1 = Father_Occupation.get()
M1 = Mother_Occupation.get()
if N1 == "" or C1 == "Select Course" or D2 == "" or Re1 == "" or S1 == "" or fathername == "" or mothername == "" or F1 == "":
messagebox.showerror("error", "Some Data is missing")
else:
file = openpyxl.load_workbook('Students_data.xlsx')
sheet = file.active
sheet.cell(row=sheet.max_row + 1, column=1, value=R1)
sheet.cell(row=sheet.max_row, column=2, value=N1)
sheet.cell(row=sheet.max_row, column=3, value=C1)
sheet.cell(row=sheet.max_row, column=4, value=G1)
sheet.cell(row=sheet.max_row, column=5, value=D2)
sheet.cell(row=sheet.max_row, column=6, value=D1)
sheet.cell(row=sheet.max_row, column=7, value=Re1)
sheet.cell(row=sheet.max_row, column=8, value=S1)
sheet.cell(row=sheet.max_row, column=9, value=fathername)
sheet.cell(row=sheet.max_row, column=10, value=mothername)
sheet.cell(row=sheet.max_row, column=11, value=F1)
sheet.cell(row=sheet.max_row, column=12, value=M1)
file.save('Students_data.xlsx')
try:
img.save("Student Images/" + str(R1) + ".jpg")
except:
messagebox.showinfo("info", "Profile picture is not available!!!!!!!!!")
messagebox.showinfo("Success", "Data saved successfully.")
clear()
def search_data(*args):
text = Search.get()
clear()
saveButton.configure(state="disable")
file = openpyxl.load_workbook('Students_data.xlsx')
sheet = file.active
for row in sheet.rows:
if row[0].value == int(text):
name = row[0]
reg_no_position = str(name)[14:-1]
reg_number = str(name)[15:-1]
try:
print(str(name))
except:
messagebox.showerror("Invalid", "Invalid registration number!!!")
x1 = sheet.cell(row=int(reg_number), column=1).value
x2 = sheet.cell(row=int(reg_number), column=2).value
x3 = sheet.cell(row=int(reg_number), column=3).value
x4 = sheet.cell(row=int(reg_number), column=4).value
x5 = sheet.cell(row=int(reg_number), column=5).value
x6 = sheet.cell(row=int(reg_number), column=6).value
x7 = sheet.cell(row=int(reg_number), column=7).value
x8 = sheet.cell(row=int(reg_number), column=8).value
x9 = sheet.cell(row=int(reg_number), column=9).value
x10 = sheet.cell(row=int(reg_number), column=10).value
x11 = sheet.cell(row=int(reg_number), column=11).value
x12 = sheet.cell(row=int(reg_number), column=12).value
Registration.set(x1)
Name.set(x2)
Course.set(x3)
if x4 == 'Male':
radio.set(1)
else:
radio.set(2)
DOB.set(x5)
Date.set(x6)
Religion.set(x7)
CNIC.set(x8)
F_Name.set(x9)
M_Name.set(x10)
Father_Occupation.set(x11)
Mother_Occupation.set(x12)
img =( Image.open("Student Images/"+str(x1)+".jpg"))
resized_image = img.resize((190, 190))
photo2 = ImageTk.PhotoImage(resized_image)
lbl.configure(image=photo2)
lbl.image = photo2
# def clear():
# Registration.set("")
# Name.set("")
# Course.set("")
# radio.set(0)
# DOB.set("")
# Date.set("")
# Religion.set("")
# CNIC.set("")
# F_Name.set("")
# M_Name.set("")
# Father_Occupation.set("")
# Mother_Occupation.set("")
# Search.set("")
# # img.set("")
# saveButton.configure(state="normal")
def update_data(*args):
global undo_history
global redo_history
R1 = Registration.get()
N1 = Name.get()
C1 = Course.get()
selection()
G1 = gender
D2 = DOB.get()
D1 = Date.get()
Re1 = Religion.get()
S1 = CNIC.get()
fathername = F_Name.get()
mothername = M_Name.get()
F1 = Father_Occupation.get()
M1 = Mother_Occupation.get()
file = openpyxl.load_workbook('Students_data.xlsx')
sheet = file.active
for row in sheet.rows:
if row[0].value == int(R1):
# sheet.cell(column=1, row=int(R1), value=int(R1))
sheet.cell(column=2, row=int(R1), value=N1)
sheet.cell(column=3, row=int(R1), value=C1)
sheet.cell(column=4, row=int(R1), value=G1)
sheet.cell(column=5, row=int(R1), value=D2)
sheet.cell(column=6, row=int(R1), value=D1)
sheet.cell(column=7, row=int(R1), value=Re1)
sheet.cell(column=8, row=int(R1), value=S1)
sheet.cell(column=9, row=int(R1), value=fathername)
sheet.cell(column=10, row=int(R1), value=mothername)
sheet.cell(column=11, row=int(R1), value=F1)
sheet.cell(column=12, row=int(R1), value=M1)
undo_history.append(sheet)
redo_history.clear()
file.save('Students_data.xlsx')
messagebox.showinfo("Success", "Data updated successfully.")
clear()
def selection(*args):
global gender
value = radio.get()
if value == 1:
gender = "Male"
else:
gender = "Female"
def delete_data(*args):
global undo_history
global redo_history
text = Search.get()
file = openpyxl.load_workbook('Students_data.xlsx')
sheet = file.active
for row in sheet.rows:
if row[0].value == int(text):
name = row[0]
reg_no_position = str(name)[14:-1]
reg_number = str(name)[15:-1]
try:
os.remove("Student Images/" + reg_number + ".jpg")
except:
pass
sheet.delete_rows(int(reg_number))
messagebox.showinfo("Success", "Data deleted successfully.")
undo_history.append(sheet)
redo_history.clear()
file.save('Students_data.xlsx')
clear()
def undo(*args):
global undo_history
global redo_history
if undo_history:
current_state = undo_history.pop()
redo_history.append(current_state)
file.save('Students_data.xlsx')
if undo_history:
current_state = undo_history[-1]
redo_history.append(current_state)
clear()
else:
messagebox.showinfo("info", "Nothing to undo.")
clear()
else:
messagebox.showinfo("info", "Nothing to undo.")
clear()
def redo(*args):
global undo_history
global redo_history
if redo_history:
current_state = redo_history.pop()
undo_history.append(current_state)
file.save('Students_data.xlsx')
if redo_history:
current_state = redo_history[-1]
undo_history.append(current_state)
clear()
else:
messagebox.showinfo("info", "Nothing to redo.")
clear()
else:
messagebox.showinfo("info", "Nothing to redo.")
clear()
def validate_dob(char, *args):
try:
datetime.strptime(DOB.get(), "%Y-%m-%d")
except ValueError:
messagebox.showerror("Error", "Invalid Date of Birth format (YYYY-MM-DD)")
root.bell()
return False
return True
def validate_email(char, *args):
email = CNIC.get()
if re.match(r"^[0-9]{5}-[0-9]{7}-[0-9]$", email):
return True
else:
messagebox.showerror("Error", "Invalid CNIC format (e.g., 12345-6789012-3)")
root.bell()
return False
CTkLabel(root, text="Email: [email protected]", width=100, height=30, bg_color="#f0687c", anchor='e').pack(side=TOP, fill=X,padx=5)
CTkLabel(root, text="STUDENT REGISTRATION", width=100, height=20, bg_color="#c36464", fg_color="#fff", font=("Arial" ,20 ,"bold")).pack(side="top", fill=X)
#search box to update
Search = StringVar()
CTkEntry(root, textvariable=Search, width=150, font=("Arial", 20)).place(x=830, y=85)
Srch = CTkButton(root, text="Search \U0001F50E", compound=LEFT, width=120,height=50, bg_color="#68ddfa", font=("Arial" ,13, "bold"),command=search_data)
Srch.place(x=1030, y=70.5)
root.bind("<Control-Key-s>",search_data)
imageicon4 = PhotoImage(file="Images/Layer 4.png")
Update_button = Button(root, image=imageicon4, bg="#c36464",command=update_data).place(x=110, y=64)
#Registration and Date
Label(root, text="Registration No.", font="Arial 13", fg=framebg, bg=background).place(x=30, y=150)
CTkLabel(root, text="Date: ", font=("Arial", 13), fg_color=framebg, bg_color=background).place(x=500, y=150)
Registration=IntVar()
Date = StringVar()
reg_entry = CTkEntry(root, textvariable=Registration, width=150, font=("Arial", 22))
reg_entry.place(x=160, y=150)
registration_no()
today = date.today()
d1 = today.strftime("%d/%m/%Y")
date_entry = CTkEntry(root, textvariable=Date, width=130, font=("Arial", 18)).place(x=540, y=150)
Date.set(d1)
#Student details
obj = LabelFrame(root, text="Student's Details", font=20, bd=2, width=900, bg=framebg, fg=framefg, height=250, relief=GROOVE)
obj.place(x=30, y=200)
Label(obj, text="Full Name:", font=("Arial", 13), bg=framebg, fg=framefg).place(x=30, y=50)
Label(obj, text="Date of Birth:", font="Arial 13", bg=framebg, fg=framefg).place(x=30, y=100)
Label(obj, text="Gender:", font="Arial 13", bg=framebg, fg=framefg).place(x=30, y=150)
Label(obj, text="Course:", font="Arial 13", bg=framebg, fg=framefg).place(x=500, y=50)
Label(obj, text="Religion:", font="Arial 13", bg=framebg, fg=framefg).place(x=500, y=100)
Label(obj, text="CNIC:", font="Arial 13", bg=framebg, fg=framefg).place(x=500, y=150)
Name=StringVar()
name_entry = CTkEntry(obj, textvariable=Name, width=190, font=("Arial", 16)).place(x=160, y=50)
DOB=StringVar()
dob_entry = CTkEntry(obj, textvariable=DOB, width=190, font=("Arial", 16)).place(x=160, y=100)
radio=IntVar()
R1=CTkRadioButton(obj, text="Male", variable=radio, value=1, bg_color=framebg, fg_color=framefg, command=selection).place(x=150, y=150)
R2=CTkRadioButton(obj, text="Female", variable=radio, value=2, bg_color=framebg, fg_color=framefg, command=selection).place(x=220, y=150)
root.bind("<Control-Key-g>",selection)
Religion=StringVar()
religion_entry = CTkEntry(obj, textvariable=Religion, width=180, font=("Arial", 16)).place(x=630, y=100)
CNIC=StringVar()
CNIC_entry = CTkEntry(obj, textvariable=CNIC, width=190, font=("Arial", 16)).place(x=630, y=150)
c1=StringVar()
Course=CTkComboBox(obj,values=['CS','SE','CE','BF','AI','PH','EE','ME','CHE','MATHS','Stats','Ds','ENG','PHY'], font=("Arial", 18), width=150,text_color="blue",corner_radius=2,dropdown_fg_color="white",dropdown_text_color="red",dropdown_font=("helvetica",15),dropdown_hover_color="blue",variable=c1)
Course.place(x=630, y=50)
Course.set("Select Course")
#Parents details
obj2 = LabelFrame(root, text="Parent's Details", font=20, bd=2, width=900, bg=framebg, fg=framefg, height=220, relief=GROOVE)
obj2.place(x=30, y=470)
Label(obj2, text="Father's Name:", font="Arial 14", bg=framebg, fg=framefg).place(x=30, y=50)
Label(obj2, text="Occupation:", font="Arial 14", bg=framebg, fg=framefg).place(x=30, y=100)
F_Name=StringVar()
f_entry = CTkEntry(obj2,textvariable=F_Name, width=190, font=("Arial", 16))
f_entry.place(x=160, y=50)
Father_Occupation=StringVar()
F0_entry = CTkEntry(obj2, textvariable=Father_Occupation, width=190, font=("Arial", 16))
F0_entry.place(x=160, y=100)
Label(obj2, text="Mother's Name:", font="Arial 14", bg=framebg, fg=framefg).place(x=500, y=50)
Label(obj2, text="Occupation:", font="Arial 14", bg=framebg, fg=framefg).place(x=500, y=100)
M_Name=StringVar()
m_entry = CTkEntry(obj2,textvariable=M_Name, width=190, font=("Arial", 16))
m_entry.place(x=630, y=50)
Mother_Occupation=StringVar()
M0_entry = CTkEntry(obj2, textvariable=Mother_Occupation, width=190, font=("Arial", 16))
M0_entry.place(x=630, y=100)
#image
f=CTkFrame(root, border_width=2, bg_color="Black", width=195, height=195)
f.place(x=1000, y=140)
img=CTkImage(Image.open("Images1/upload photo.png"),size=(216,222))
lbl=CTkLabel(f, bg_color="Black", image=img,text="")
lbl.place(x=0, y=0)
#button
CTkButton(root, text="Upload", width=190, height=50, font=("Arial", 14,"bold"), bg_color="lightblue", command=showimage,hover_color="grey").place(x=1000, y=360)
root.bind("<Control-Key-u>",showimage)
saveButton = CTkButton(root, text="Save", width=190, height=50, font=("Arial" ,14, "bold"), bg_color="lightgreen",command=save_data,hover_color="green")
saveButton.place(x=1000, y=495)
root.bind("<Button-3>",save_data)
# CTkButton(root, text="Reset", width=190, height=50, font=("Arial", 12, "bold"), bg_color="lightpink",command=reset_form).place(x=1000, y=580)
# root.bind("<Control-Key-r>",reset_form)
CTkButton(root, text="Exit", width=190, height=50, font=("Arial", 14, "bold"), bg_color="grey", command=Exit,hover_color="red").place(x=1000, y=620)
root.bind("<Control-Key-Escape>",Exit)
clearButton = CTkButton(root, text="Clear Data", width=190, height=50, font=("Arial", 14, "bold"), bg_color="lightblue", command=clear,cursor="hand2",hover_color="white")
clearButton.place(x=680, y=150)
root.bind("<Control-Key-c>",clear)
# Undo and Redo buttons
undoButton = CTkButton(root, text="Undo", width=190, height=50, font=("Arial", 14, "bold"), bg_color="lightgray", command=undo,hover_color="grey")
undoButton.place(x=1000, y=425)
root.bind("<Control-Key-z>",undo)
redoButton = CTkButton(root, text="Redo", width=190, height=50, font=("Arial", 14, "bold"), bg_color="lightgray", command=redo,hover_color="grey")
redoButton.place(x=1000, y=555)
root.bind("<Control-Key-r>",redo)
root.mainloop()