-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmain.py
431 lines (339 loc) · 15.1 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
from tkinter import *
from tkinter import ttk
from tkinter import messagebox
from datetime import datetime as time
from datetime import date
import mysql.connector as mysql
import dbconnect as db
days = ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"]
def main():
global main_screen
main_screen = Tk()
main_screen.geometry("300x260")
main_screen.title("Main")
Label(text="Select Yourself,", bg="#b1abf1", fg="white",
width="300", height="2", font=("Calibri", 13)).pack(padx=20, pady=23 )
Button(text="Faculty", height="2", width="15", fg="#c0ecc0",command=facultylogin).pack(padx=1, pady=20)
Button(text="Student", height="2", width="15",fg="#D8BFD8", command=studentlogin).pack(padx=1, pady=5)
main_screen.mainloop()
def studentlogin():
main_screen.destroy()
global login_screen
login_screen = Tk()
login_screen.title("Student Login")
login_screen.geometry("320x350")
Label(login_screen,text="Enter Login Details",bg="#c0ecc0", fg="black",
width="300", height="2",font=("Calibri", 13)).pack(padx=20, pady=23 )
Label(login_screen, text="").pack()
global rollno_verify
global password_verify
rollno_verify = StringVar()
password_verify = StringVar()
global rollno_login_entry
global password_login_entry
Label(login_screen, text="Roll no.",fg="black", bg="#c0ecc0").pack()
rollno_login_entry = Entry(login_screen, textvariable=rollno_verify)
rollno_login_entry.pack(pady=5)
Label(login_screen, text="").pack()
Label(login_screen, text="Password",fg="black", bg="#c0ecc0").pack(pady=5)
password_login_entry = Entry(login_screen, textvariable=password_verify, show='*')
password_login_entry.pack()
Label(login_screen, text="").pack()
Button(login_screen, text="Back",width=10,fg="black" ,height=1, command=backtomain).pack(padx=(0,70), side=RIGHT)
Button(login_screen, text="Login",width=10,fg="black" ,height=1, command=student_login_verify).pack(padx=(70,0), side=LEFT)
login_screen.mainloop()
def facultylogin():
main_screen.destroy()
global login_screen
login_screen = Tk()
login_screen.title("Professor Login")
login_screen.geometry("320x350")
Label(login_screen,text="Enter Login Details",bg="#c0ecc0", fg="black",
width="300", height="2",font=("Calibri", 13)).pack(padx=20, pady=23 )
Label(login_screen, text="").pack()
global profid_verify
global password_verify
profid_verify = StringVar()
password_verify = StringVar()
global profid_login_entry
global password_login_entry
Label(login_screen, text="Professor ID",fg="black", bg="#c0ecc0").pack()
profid_login_entry = Entry(login_screen, textvariable=profid_verify)
profid_login_entry.pack(pady=5)
Label(login_screen, text="").pack()
Label(login_screen, text="Password",fg="black", bg="#c0ecc0").pack(pady=5)
password_login_entry = Entry(login_screen, textvariable=password_verify, show='*')
password_login_entry.pack()
Label(login_screen, text="").pack()
Button(login_screen, text="Back",width=10,fg="black" ,height=1, command=backtomain).pack(padx=(0,70), side=RIGHT)
Button(login_screen, text="Login",width=10,fg="black" ,height=1, command=faculty_login_verify).pack(padx=(70,0), side=LEFT)
login_screen.mainloop()
def backtomain():
login_screen.destroy()
main()
def student_login_verify():
rollno = rollno_verify.get()
password = password_verify.get()
rollno_login_entry.delete(0, END)
password_login_entry.delete(0, END)
if rollno == "" or password == "":
messagebox.showerror("Information",'Error Enter username & password')
else:
try:
conn = mysql.connect(**db.dbConfig)
cursor = conn.cursor(buffered=True)
cursor.execute("select name from students where roll_no=%s and password=%s", (rollno, password))
rowcount = cursor.rowcount
if rowcount == 1:
messagebox.showinfo('Information', "Login Successfully")
for name in cursor:
Name = name[0]
student_dashboard(rollno,Name)
else:
messagebox.showinfo('Information', "Login failed,Invalid Username or Password.Try again!!!")
cursor.close()
conn.close()
except Exception as es:
messagebox.showinfo('Error', f"due to :{str(es)}")
def faculty_login_verify():
profid = profid_verify.get()
password = password_verify.get()
profid_login_entry.delete(0, END)
password_login_entry.delete(0, END)
if(profid == "ADMIN" and password == "terabaap"):
admin_dasboard()
if profid == "" or password == "":
messagebox.showerror("Information",'Error Enter username & password')
else:
try:
conn = mysql.connect(**db.dbConfig)
cursor = conn.cursor(buffered=True)
cursor.execute("select name from professors where prof_id=%s and password=%s", (profid, password))
rowcount = cursor.rowcount
if rowcount == 1:
messagebox.showinfo('Information', "Login Successfully")
for name in cursor:
Name = name[0]
faculty_dashboard(profid,Name)
else:
messagebox.showinfo('Information', "Login failed,Invalid Username or Password.Try again!!!")
cursor.close()
conn.close()
except Exception as es:
messagebox.showinfo('Error', f"due to :{str(es)}")
def admin_dasboard():
login_screen.destroy()
global dashboard
dashboard = Tk()
dashboard.title("Welcome Admin,")
dashboard.geometry("300x500")
Label(text="Dashboard", bg="#b1abf1", fg="white",
width="300", height="2", font=("Calibri", 13)).pack(padx=20, pady=23 )
Button(text="Institute Courses", height="2", width="15", fg="#c0ecc0",command=allcourses).pack(padx=1, pady=(20,5))
# Button(text="Add Faculty", height="2", width="15",fg="#D8BFD8", command=student_courses).pack(padx=1, pady=5)
# Button(text="Add Student", height="2", width="15",fg="#D8BFD8", command=student_courses).pack(padx=1, pady=5)
# Button(text="Add Course", height="2", width="15",fg="#D8BFD8", command=student_courses).pack(padx=1, pady=5)
# Button(text="Add Schedule", height="2", width="15",fg="#D8BFD8", command=student_courses).pack(padx=1, pady=5)
Button(text="Logout", height="2", width="15",fg="#D8BFD8", command=dashboardtomain).pack(padx=1, pady=5)
dashboard.mainloop()
def allcourses():
global courses_dasboard
courses_dasboard = Toplevel(dashboard)
courses_dasboard.title("Courses")
courses_dasboard.geometry("300x350")
c = Frame(courses_dasboard)
c.pack()
Label(c, text="All Courses", bg="#b1abf1", fg="white",
width="300", height="2", font=("Calibri", 13)).pack(padx=20, pady=23 )
#scrollbar
cscroll = Scrollbar(c)
cscroll.pack(side=RIGHT, fill=Y)
C = ttk.Treeview(c,yscrollcommand=cscroll.set)
C.pack()
cscroll.config(command=C.yview)
#define our column
C['columns'] = ('Course_Code', 'Course_Name') # get column names from database
# format our column
C.column("#0", width=0, stretch=NO)
C.column("Course_Code",anchor=CENTER, width=80)
C.column("Course_Name",anchor=CENTER,width=80)
#Create Headings
C.heading("#0",text="",anchor=CENTER)
C.heading("Course_Code",text="Course code",anchor=CENTER)
C.heading("Course_Name",text="Course name",anchor=CENTER)
#add data
conn = mysql.connect(**db.dbConfig)
cursor = conn.cursor(buffered=True)
cursor.execute("select course_code, course_name from courses")
for coursecode, coursename in cursor:
print(coursecode, coursename)
C.insert(parent='',index='end',text='', values=(coursecode, coursename))
C.pack()
cursor.close()
conn.close()
def student_dashboard(rollno,name):
login_screen.destroy()
global dashboard
dashboard = Tk()
dashboard.title("Welcome {}".format(name))
dashboard.geometry("300x350")
Label(text="Dashboard", bg="#b1abf1", fg="white",
width="300", height="2", font=("Calibri", 13)).pack(padx=20, pady=23)
Button(text="Attendence", height="2", width="15", fg="#c0ecc0",command=lambda: Attendence(rollno)).pack(padx=1, pady=(20,5))
Button(text="My Courses", height="2", width="15",fg="#D8BFD8", command=lambda: student_courses(rollno)).pack(padx=1, pady=5)
Button(text="Logout", height="2", width="15",fg="#D8BFD8", command=dashboardtomain).pack(padx=1, pady=5)
dashboard.mainloop()
def faculty_dashboard(profid, name):
login_screen.destroy()
global dashboard
dashboard = Tk()
dashboard.title("Welcome {}".format(name))
dashboard.geometry("300x400")
Label(text="Dashboard", bg="#b1abf1", fg="white",
width="300", height="2", font=("Calibri", 13)).pack(padx=20, pady=23)
Button(text="My Courses", height="2", width="15",fg="#D8BFD8", command=lambda: faculty_courses(profid)).pack(padx=1, pady=5)
Button(text="Student's Attendence", height="2", width="15",fg="#D8BFD8", command=lambda: student_attendence(profid)).pack(padx=1, pady=5)
Button(text="Logout", height="2", width="15",fg="#D8BFD8", command=dashboardtomain).pack(padx=1, pady=5)
dashboard.mainloop()
def dashboardtomain():
dashboard.destroy()
main()
def Attendence(rollno):
now = time.now()
day = now.weekday()
hour = now.hour
minute = now.minute
tnow = "{}:00:00".format(hour)
conn = mysql.connect(**db.dbConfig)
cursor = conn.cursor(buffered=True)
cursor.execute("select course_code from courses_taken where roll_no=%s and course_code in (select course_code from courses_sch where day=%s and start_time=%s)", (rollno, day, tnow))
if(cursor.rowcount == 0):
cursor.close()
conn.close()
messagebox.showerror("Information","You have no Lectures at this moment")
return
for course_code in cursor:
course = course_code[0]
cursor.execute("select course_name from courses where course_code=%s", (course,))
course_name = ""
for cc in cursor:
course_name = cc[0]
cursor.execute("insert into attendance (roll_no, course_code, date) values (%s, %s, %s)", (rollno, course, date.today()))
cursor.close()
conn.close()
messagebox.showinfo("Attendence Marked", "Your attendence for {} course is marked at time {}:{} {}".format(course_name, hour, minute, days[day]))
def student_courses(rollno):
global courses
courses = Toplevel(dashboard)
courses.title("Your courses")
courses.geometry("300x350")
c = Frame(courses)
c.pack()
Label(c, text="Courses", bg="#b1abf1", fg="white",
width="300", height="2", font=("Calibri", 13)).pack(padx=20, pady=23 )
#scrollbar
cscroll = Scrollbar(c)
cscroll.pack(side=RIGHT, fill=Y)
C = ttk.Treeview(c,yscrollcommand=cscroll.set)
C.pack()
cscroll.config(command=C.yview)
#define our column
C['columns'] = ('Course_Code', 'Course_Name') # get column names from database
# format our column
C.column("#0", width=0, stretch=NO)
C.column("Course_Code",anchor=CENTER, width=80)
C.column("Course_Name",anchor=CENTER,width=80)
#Create Headings
C.heading("#0",text="",anchor=CENTER)
C.heading("Course_Code",text="Course code",anchor=CENTER)
C.heading("Course_Name",text="Course name",anchor=CENTER)
#add data
conn = mysql.connect(**db.dbConfig)
cursor = conn.cursor(buffered=True)
cursor.execute("select course_code, course_name from courses where course_code in (select course_code from courses_taken where roll_no=%s)", (rollno,))
for coursecode, coursename in cursor:
print(coursecode, coursename)
C.insert(parent='',index='end',text='', values=(coursecode, coursename))
C.pack()
cursor.close()
conn.close()
def faculty_courses(profid):
global courses
courses = Toplevel(dashboard)
courses.title("Your courses")
courses.geometry("300x350")
c = Frame(courses)
c.pack()
Label(c, text="Courses", bg="#b1abf1", fg="white",
width="300", height="2", font=("Calibri", 13)).pack(padx=20, pady=23 )
#scrollbar
cscroll = Scrollbar(c)
cscroll.pack(side=RIGHT, fill=Y)
C = ttk.Treeview(c,yscrollcommand=cscroll.set)
C.pack()
cscroll.config(command=C.yview)
#define our column
C['columns'] = ('Course_Code', 'Course_Name') # get column names from database
# format our column
C.column("#0", width=0, stretch=NO)
C.column("Course_Code",anchor=CENTER, width=80)
C.column("Course_Name",anchor=CENTER,width=80)
#Create Headings
C.heading("#0",text="",anchor=CENTER)
C.heading("Course_Code",text="Course code",anchor=CENTER)
C.heading("Course_Name",text="Course name",anchor=CENTER)
#add data
conn = mysql.connect(**db.dbConfig)
cursor = conn.cursor(buffered=True)
cursor.execute("select course_code, course_name from courses where prof_id=%s", (profid,))
for coursecode, coursename in cursor:
print(coursecode, coursename)
C.insert(parent='',index='end',text='', values=(coursecode, coursename))
C.pack()
cursor.close()
conn.close()
def student_attendence(profid):
global attendence_dashboard
attendence_dashboard = Toplevel(dashboard)
attendence_dashboard.title("Attendence dashboared")
attendence_dashboard.geometry("500x450")
c = Frame(attendence_dashboard)
c.pack()
Label(c, text="Courses", bg="#b1abf1", fg="white",
width="300", height="2", font=("Calibri", 13)).pack(padx=20, pady=23 )
#scrollbar
cscroll = Scrollbar(c)
cscroll.pack(side=RIGHT, fill=Y)
C = ttk.Treeview(c,yscrollcommand=cscroll.set)
C.pack()
cscroll.config(command=C.yview)
#define our column
C['columns'] = ('Course_Code', 'Attendence') # get column names from database
# format our column
C.column("#0", width=0, stretch=NO)
C.column("Course_Code",anchor=CENTER, width=80)
C.column("Attendence",anchor=CENTER,width=80)
#Create Headings
C.heading("#0",text="",anchor=CENTER)
C.heading("Course_Code",text="Course code",anchor=CENTER)
C.heading("Attendence",text="Attendence count",anchor=CENTER)
Label(c, text="").pack()
global rollno_verify
rollno_verify = StringVar()
Label(c, text="Students roll no.",fg="black", bg="#c0ecc0").pack(pady=1)
rollno_login_entry = Entry(c, textvariable=rollno_verify)
rollno_login_entry.pack(pady=5)
Button(c, text="Go",width=5,fg="black" ,height=1, command=lambda: tableattendance(C,profid)).pack(padx=2)
def tableattendance(C,profid):
rollno = rollno_verify.get()
for row in C.get_children():
C.delete(row)
conn = mysql.connect(**db.dbConfig)
cursor = conn.cursor(buffered=True)
cursor.execute("select course_code, count(attend_id) as count from attendance where roll_no=%s and course_code in (select course_code from courses where prof_id=%s) group by course_code", (rollno,profid))
for coursecode, count in cursor:
C.insert(parent='',index='end',text='', values=(coursecode, count))
C.pack()
cursor.close()
conn.close()
main()