You are on page 1of 87

ARMY PUBLIC SCHOOL

ASC C&C, BANGALORE

TEACHER ATTENDANCE
MANAGEMENT SYSTEM

INFORMATICS PRACTICES – 065


PROJECT

CLASS XII
2021-2022
Page 1 of 87
ARMY PUBLIC SCHOOL
ASC C&C, BANGALORE

Name: Roll Number:


Class : XII Section :

This is to certify that the project entitled as


________________________ is a bonafide work of
________________________ in the subject of Informatics
Practices during the academic year 2021-2022.

_______________ ________________
Internal Examiner External Examiner

Date: ________________
Principal

Page 2 of 87
ACKNOWLEDGEMENT

I sincerely extend my deepest gratitude to our principal Dr.


Upasana Yadav for providing us with all the facilities and kind
moral support for carrying out this project work.

I would like to express my special thanks of gratitude to my


teacher Mr. Helvin M Geevar, PGT Computer Science who
gave me the golden opportunity to do this wonderful project
which also helped me in doing a lot of research and I came to
know about so many new things, I would also like to thank the
computer instructor Mr. Sajith TM who provided technical
support while conducting experiments in the lab.

I would also like to thank my parents and friends who helped me


a lot in finishing this project within the limited time.

Page 3 of 87
TABLE OF CONTENTS

SERIAL DESCRIPTION PAGE NO.


NO.
1. Introduction 5
2. Synopsis 6
3. System Analysis 8
4. System Design 10
5. System 15
Requirements
6. Screenshots 16
7. Source Code 21
8. Conclusion 87
9. Project Members 88
10. Reference 89

INTRODUCTION

Page 4 of 87
In this modern era of computer technology software plays an
important part. It has been really a tedious task to automate
everything manually, where the data is maintained as hardcopy
or a softcopy. Even if we try to automate it through any of the
application software available, we find it very difficult to
manipulate the data.
Here we have made a serious effort to automate the work
through this software. Our application helps to register the
teachers’ details and their attendance through face recognition
system and also show the visuals representation of data through
graph.
Facial recognition is a way of identifying or confirming an
individual’s identity using their face. Facial recognition systems
can be used to identify people in photos, videos, or in real-time.
Facial recognition is a category of biometric security. The
technology is mostly used for security and law enforcement,
though there is increasing interest in other areas of use.

Page 5 of 87
SYNOPSIS

Teacher’s face recognition attendance system (TFRA) is an open


platform for Teachers, Face recognition is a personal
identification system that uses personal characteristics of a
person to identify the person's identity and their details. It has
been made graphically attractive, easily manageable and user-
friendly using the Tkinter, which is the GUI library for the
python programming language. Meanwhile Teacher’s face
recognition system also uses CSV and SQL for database
management for the entries of the details of different users.
A CSV file typically stores tabular data (numbers and text) in
plain text, in which case each line will have the same number of
fields. Face recognition procedure basically consists of two
phases, namely face detection, where this process takes a sample
of the user by clicking a picture of it. It provides the user to
register their attendance without any physical contact. The
program basically a takes a sample of image of different users.
Different image of users are already been register to just match
the attendance program. We can also see the user’s data and
their details.

Page 6 of 87
In this pandemic situation its best to avoid physical contacts so
here we are with our face recognition system which will help to
register the user their attendance without any physical contact.

The software has the following modules:


 MySQL Connector
 OpenCV
 Pandas
 Matplotlib
 Numpy
 Tkinter
We have used Face Recognition library to detect the
face as it is one of the most popular library.
Recognize and manipulate faces from Python or from the
command line with the world’s simplest face recognition library.
Built using dlib’s state-of-the-art face recognition
built with deep learning. The model has an accuracy of 99.38%
on the

Dlib is a general purpose cross-platform software library written


in the programming language.  Its design is heavily influenced by
ideas from design by contract and component-based software
engineering. Thus it is, first and foremost, a set of independent
software components. It is open-source software released under
a Boost Software License.
Page 7 of 87
SYSTEM ANALYSIS

1. Existing System
The present technology is based on fingerprint sensor.
Following are the disadvantages of Fingerprint sensor:
 The system has inability to enroll some users.
 The accuracy and working of system is affected by skin
conditions of people.
 The system is associated with forensic applications.
 There are health issues involved due to touching of
single scanning sensor device by countless number of
individuals. This has serious implications in pandemic
situations such as COVID-19 etc.
 It is difficult to capture complete and accurate fingerprint
image in some cases based on age and occupation.
 Collection of high-quality nails to nail image needs
training and specific skills.

Page 8 of 87
2. PROPOSED SYSTEM
The project is developed in Python, which mainly focuses on
attendance management and storing teachers’ details. This
application is a highly reliable one, with user friendly and
attractive interface.
The following are features of proposed system:
 User friendly interface.
 Fast access to database.
 Face recognition.
 Storage capacity.
 Visual presentation

SYSTEM DESIGN

1. OUTPUT FORM DESIGN


Page 9 of 87
Computer output is the most important and direct source of
information to the user. Efficient, intelligible output design
should be improve the system relationship with the user and
help in decision making. The outputs provide in the system
are the softcopy report available for printing. Printouts should
design around from the output requirement of the user. The
output devices to consider depend on the factor such as
compatibility of the device with the system, response time
requirement and number of copies needed.

2. INPUT FORM DESIGN


Input design is the process of converting user originated
computer based format. Inaccurate input data are the most
common cause of errors in data processing. Errors entered by
data entry operators can be controlled by input design. The
goal of designing input data is to make data entry as easy,
logical and free from errors as far as possible. In this system,
the input screens are developed according to the user
requirements

3. DATABASE DESIGN
The general theme behind a database is to handle information
as an integrated whole. A database is a collection of
interrelated data stored with designing the input and output,
analyst must concentrate on database design or how data

Page 10 of 87
should be organized around user requirements. The general
objective is to make information access, easy quick,
inexpensive and flexible for other user.
During database design the following objectives are
concerned.
 Controlled Redundancy
 Easy to learn and use
 More information and low cost
 Accuracy
 Integrity

TABLES USED

Table Name : Register


Primary Key : Email
Page 11 of 87
Field Name Data Type Size
First_Name VARCHAR 45

Last_Name VARCHAR 45
Contact_No BIGINT -
Email VARCHAR 45
Security_Q VARCHAR 45

Security_A VARCHAR 45
Password VARCHAR 45

Table Name : Teacher


Primary Key : Teacher_ID

Page 12 of 87
Field Name Data Type Size
Department VARCHAR 45
Category VARCHAR 45
Year VARCHAR 45
Semester VARCHAR 45
Teacher_ID INT -
Teacher_Name VARCHAR 45
Class_Teacher VARCHAR 45
Table_No VARCHAR 45
Gender VARCHAR 45
DOB VARCHAR 45
Email VARCHAR 45
Phone BIGINT -
Address VARCHAR 45
Staff_Room_No INT -
Photo_Sample VARCHAR 45

Table Name : Issues


Primary Key : S_No

Page 13 of 87
Field Name Data Type Size

S_No INT -

Name VARCHAR 45

Email VARCHAR 45

Contact_No BIGINT -

Issue VARCHAR 45

SYSTEM REQUIREMENTS

1. HARDWARE REQUIREMENTS
Page 14 of 87
 Processor : Intel Pentium IV 2.4GHZ or above
 Clock speed : 500MHZ
 RAM : 1GB of RAM
 HDD : 40GB or higher
 Monitor : SVGA Color
 Keyboard : 108 keys
 Mouse : 2 button mouse
 Webcam : High Resolution

2. SYSTEM REQUIREMENTS

 Operating System : MS WINDOWS 7 or Above


 Environment : VS Code
 Front end : Python 3.9.0
 Back end : csv

SCREENSHOTS
MySQL Credentials

Page 15 of 87
Login Window

Register Window

Page 16 of 87
Main Window

Teacher Details Window

Page 17 of 87
Face Recognition Window

Attendance Window

Page 18 of 87
Help Window

Graph Window

Page 19 of 87
SOURCE CODE
from tkinter import *
from tkinter import ttk, messagebox

Page 20 of 87
from PIL import Image, ImageTk
from tkcalendar import DateEntry
import mysql.connector as sql
import face_recognition
from time import strftime
from datetime import datetime
import os
import pandas as pd
import matplotlib.pyplot as plt
import cv2
import csv
import numpy as np
class Login_Window:
def __init__(self):
self.root = Tk()
self.root.state('zoomed')
self.root.resizable(False, False)
self.root.iconbitmap(r"Images\login_logo.ico")
self.root.title("LOGIN")
img1 = Image.open(r"Images\bg.jpg")
img1 = img1.resize((1362, 764), Image.ANTIALIAS)
self.photoimg1 = ImageTk.PhotoImage(img1)
f_lbl = Label(self.root, image=self.photoimg1)

Page 21 of 87
f_lbl.place(x=0, y=0)
frame = Frame(self.root, bg="cyan")
frame.place(x=500, y=150, width=340, height=450)
img2 = Image.open(r"Images\login_img.png")
img2 = img2.resize((100, 70), Image.ANTIALIAS)
self.photoimg2 = ImageTk.PhotoImage(img2)
f_lbl = Label(frame, image=self.photoimg2)
f_lbl.place(x=120, y=2)
get_str = Label(frame, text="GET STARTED",
font=("Cascadida Code", 15, "bold"), fg="black", bg="cyan")
get_str.place(x=102, y=75)
username_lbl = Label(frame, text="Username:",
font=("Cascadia Code", 15, "bold"), fg="white", bg="green")
username_lbl.place(x=70, y=115)
self.var_username = StringVar()
username_entry = ttk.Entry(frame,
textvariable=self.var_username, font=("Cascadia Code", 15,
"bold"))
username_entry.place(x=40, y=150, width=270)
username_entry.focus()
password_lbl = Label(frame, text="Password:",
font=("Cascadia Code", 15, "bold"), fg="white", bg="green")
password_lbl.place(x=70, y=200)
self.var_password = StringVar()

Page 22 of 87
pass_entry = ttk.Entry(frame,
textvariable=self.var_password, show="*", font=("Cascadia
Code", 15, "bold"))
pass_entry.place(x=40, y=235, width=270)
img3 = Image.open(r"Images\username_img.jpg")
img3 = img3.resize((25, 29), Image.ANTIALIAS)
self.photoimg3 = ImageTk.PhotoImage(img3)
f_lbl = Label(frame, image=self.photoimg3)
f_lbl.place(x=41, y=115)
img4 = Image.open(r"Images\lock.jpg")
img4 = img4.resize((25, 29), Image.ANTIALIAS)
self.photoimg4 = ImageTk.PhotoImage(img4)
f_lbl = Label(frame, image=self.photoimg4)
f_lbl.place(x=41, y=200)
login_btn = Button(frame, text="LOGIN",
command=self.login, cursor="hand2", font=("Cascadia Code", 12,
"bold"), bd=3, relief=RIDGE, fg="white", bg="red",
activeforeground="white", activebackground="red")
login_btn.place(x=110, y=290, width=120, height=35)
self.root.bind("<Return>", self.login)
register_btn = Button(frame, text="REGISTER OR DELETE
ACCOUNT", cursor="hand2", command=self.register_data,
font=("Cascadia Code", 12, "bold underline"), borderwidth=0,
fg="black", bg="cyan", activeforeground="white",
activebackground="black")
register_btn.place(x=54, y=340, width=235, height=35)
Page 23 of 87
forgot_pass_btn = Button(frame, text="FORGOT
PASSWORD", command=self.forgot_password, cursor="hand2",
font=("Cascadia Code", 12, "bold underline"), borderwidth=0,
fg="black", bg="cyan", activeforeground="white",
activebackground="black")
forgot_pass_btn.place(x=95, y=390, width=150, height=35)
self.root.protocol("WM_DELETE_WINDOW", self.exit_func)
self.root.mainloop()
def exit_func(self):
self.msg = messagebox.askyesno("Attendance Mangement",
"Are you sure you want to exit?", parent=self.root)
if self.msg == 1:
self.root.destroy()
def login(self, event=""):
if self.var_username.get() == "" or self.var_password.get()
== "":
messagebox.showerror("ERROR!", "All fields are
required!", parent=self.root)
else:
my_cursor.execute("SELECT * FROM Register WHERE
Email=%s AND Password=%s", (self.var_username.get(),
self.var_password.get()))
row = my_cursor.fetchone()
if row == None:
messagebox.showerror("ERROR!", "Invalid Username
or Password", parent=self.root)

Page 24 of 87
else:
messagebox.showinfo("SUCCESS!", "Access
Granted!", parent=self.root)
self.root.destroy()
Main_Window()
def forgot_password(self):
if self.var_username.get() == "":
messagebox.showerror("ERROR!", "Please enter the
username to reset password!", parent=self.root)
else:
my_cursor.execute("SELECT * FROM Register WHERE
Email=%s", (self.var_username.get(),))
row = my_cursor.fetchone()
if row == None:
messagebox.showerror("ERROR!", "Invalid Username",
parent=self.root)
else:
self.root2 = Toplevel()
self.root2.overrideredirect(True)
self.root2.attributes('-topmost',True)
self.root2.geometry("340x455+500+170")
lbl = Label(self.root2, text="FORGOT PASSWORD",
font=("Cascadia Code", 15, "bold"), fg="red", bg="white")
lbl.place(x=0, y=10, relwidth=1)

Page 25 of 87
sec_q = Label(self.root2, text="Select Security
Question:", font=("Cascadia Code", 15, "bold"))
sec_q.place(x=15, y=80)
self.var_sec_ques = StringVar()
sec_q_combo = ttk.Combobox(self.root2,
textvariable=self.var_sec_ques, font=("Cascadia Code", 15,
"bold"), width=24, state="readonly")
sec_q_combo["values"] = ("Select", "Your Birth Place?",
"Your Favourite Car?", "Your Pet Name?", "Your School Name?")
sec_q_combo.current(0)
sec_q_combo.place(x=15, y=110)
sec_a = Label(self.root2, text="Security Answer:",
font=("Cascadia Code", 15, "bold"))
sec_a.place(x=15, y=150)
self.var_sec_ans = StringVar()
sec_a_entry = ttk.Entry(self.root2,
textvariable=self.var_sec_ans, font=("Cascadia Code", 15,
"bold"), width=27)
sec_a_entry.place(x=15, y=180)
new_password = Label(self.root2, text="New
Password:", font=("Cascadia Code", 15, "bold"))
new_password.place(x=15, y=220)
self.var_new_pass = StringVar()
new_password_entry = ttk.Entry(self.root2,
textvariable=self.var_new_pass, show="*", font=("Cascadia
Code", 15, "bold"), width=25)

Page 26 of 87
new_password_entry.place(x=15, y=250)
btn = Button(self.root2, text="RESET",
command=self.reset_password, cursor="hand2", font=("Cascadia
Code", 15, "bold"), fg="white", bg="green")
btn.place(x=135, y=300)
self.root2.bind("<Return>", self.reset_password)
btn2 = Button(self.root2, text="EXIT",
command=self.root2.destroy, cursor="hand2", font=("Cascadia
Code", 15, "bold"), fg="white", bg="red")
btn2.place(x=141, y=380)
def reset_password(self, event=""):
if self.var_sec_ques.get() == "Select" or
self.var_sec_ans.get() == "" or self.var_new_pass.get() == "":
messagebox.showerror("ERROR!", "All fields are
required!", parent=self.root2)
else:
my_cursor.execute("SELECT * FROM Register WHERE
Email=%s AND Security_Q=%s AND Security_A=%s",
(self.var_username.get(), self.var_sec_ques.get(),
self.var_sec_ans.get()))
row = my_cursor.fetchone()
if row == None:
messagebox.showerror("ERROR!", "Please enter the
correct question and answer!", parent=self.root2)
else:

Page 27 of 87
my_cursor.execute("UPDATE Register SET Password=
%s WHERE Email=%s", (self.var_new_pass.get(),
self.var_username.get()))
conn.commit()
messagebox.showinfo("SUCCESS!", "Your password
has been reset!", parent=self.root2)
self.root2.destroy()
def reset_data(self):
self.var_username.set("")
self.var_password.set("")
def register_data(self):
self.reset_data()
self.new_window = Toplevel(self.root)
self.app = Register(self.new_window)
class Register:
def __init__(self, root):
self.root = root
self.root.state('zoomed')
self.root.resizable(False, False)
self.root.iconbitmap(r"Images\register_logo.ico")
self.root.title("REGISTER")
img1 = Image.open(r"Images\bg.jpg")
img1 = img1.resize((1362, 764), Image.ANTIALIAS)
self.photoimg1 = ImageTk.PhotoImage(img1)

Page 28 of 87
f_lbl = Label(self.root, image=self.photoimg1)
f_lbl.place(x=0, y=0)
img2 = Image.open(r"Images\reg_img.jpg")
img2 = img2.resize((400, 500), Image.ANTIALIAS)
self.photoimg2 = ImageTk.PhotoImage(img2)
f_lbl = Label(self.root, image=self.photoimg2)
f_lbl.place(x=50, y=100)
frame = Frame(self.root, bg="white")
frame.place(x=452, y=102, width=800, height=500)
register_lbl = Label(frame, text="REGISTER HERE",
font=("Cascadia Code", 25, "bold"), fg="darkgreen", bg="white")
register_lbl.place(x=20, y=20)
in_frame = Frame(self.root)
in_frame.place(x=475, y=175, width=700, height=410)
f_name = Label(in_frame, text="First Name:",
font=("Cascadia Code", 15, "bold"))
f_name.grid(row=0, column=0, sticky=W)
self.var_fname = StringVar()
f_name_entry = ttk.Entry(in_frame,
textvariable=self.var_fname, font=("Cascadia Code", 15, "bold"),
width=25)
f_name_entry.grid(row=1, column=0, padx=(0, 50),
sticky=W)
f_name_entry.focus()

Page 29 of 87
l_name = Label(in_frame, text="Last Name:",
font=("Cascadia Code", 15, "bold"))
l_name.grid(row=0, column=1, sticky=W)
self.var_lname = StringVar()
l_name_entry = ttk.Entry(in_frame,
textvariable=self.var_lname, font=("Cascadia Code", 15, "bold"),
width=25)
l_name_entry.grid(row=1, column=1)
contact_no = Label(in_frame, text="Contact No:",
font=("Cascadia Code", 15, "bold"))
contact_no.grid(row=2, column=0, sticky=W)
self.var_contact = StringVar()
contact_no_entry = ttk.Entry(in_frame,
textvariable=self.var_contact, font=("Cascadia Code", 15, "bold"),
width=25)
contact_no_entry.grid(row=3, column=0, padx=(0, 50),
sticky=W)
email = Label(in_frame, text="Username:", font=("Cascadia
Code", 15, "bold"))
email.grid(row=2, column=1, sticky=W)
self.var_email = StringVar()
email_entry = ttk.Entry(in_frame, textvariable=self.var_email,
font=("Cascadia Code", 15, "bold"), width=25)
email_entry.grid(row=3, column=1)
sec_q = Label(in_frame, text="Select Security Question:",
font=("Cascadia Code", 15, "bold"))

Page 30 of 87
sec_q.grid(row=4, column=0, sticky=W, padx=(0, 50))
self.var_sec_q = StringVar()
sec_q_combo = ttk.Combobox(in_frame,
textvariable=self.var_sec_q, font=("Cascadia Code", 15, "bold"),
width=24, state="readonly")
sec_q_combo["values"] = ("Select", "Your Birth Place?",
"Your Favourite Car?", "Your Pet Name?", "Your School Name?")
sec_q_combo.current(0)
sec_q_combo.grid(row=5, column=0, sticky=W)
sec_a = Label(in_frame, text="Security Answer:",
font=("Cascadia Code", 15, "bold"))
sec_a.grid(row=4, column=1, sticky=W)
self.var_sec_a = StringVar()
sec_a_entry = ttk.Entry(in_frame,
textvariable=self.var_sec_a, font=("Cascadia Code", 15, "bold"),
width=25)
sec_a_entry.grid(row=5, column=1)
password = Label(in_frame, text="Password:",
font=("Cascadia Code", 15, "bold"))
password.grid(row=6, column=0, sticky=W)
self.var_pass = StringVar()
password_entry = ttk.Entry(in_frame,
textvariable=self.var_pass, show="*", font=("Cascadia Code", 15,
"bold"), width=25)
password_entry.grid(row=7, column=0, padx=(0, 20),
sticky=W)

Page 31 of 87
c_password = Label(in_frame, text="Confirm Password:",
font=("Cascadia Code", 15, "bold"))
c_password.grid(row=6, column=1, sticky=W)
self.var_con_pass = StringVar()
c_password_entry = ttk.Entry(in_frame,
textvariable=self.var_con_pass, show="*", font=("Cascadia
Code", 15, "bold"), width=25)
c_password_entry.grid(row=7, column=1)
self.var_check = IntVar()
check_btn = Checkbutton(in_frame, text="I Agree the Terms
and Conditions", variable=self.var_check, font=("Cascadia Code",
15, "bold"), onvalue=1, offvalue=0)
check_btn.place(x=100, y=300)
self.var_check.set(1)
img3 = Image.open(r"Images\reg_btn.png")
img3 = img3.resize((200, 85), Image.ANTIALIAS)
self.photoimg3 = ImageTk.PhotoImage(img3)
b1 = Button(in_frame, image=self.photoimg3,
command=self.register_data, borderwidth=0, cursor="hand2",
font=("Cascadia Code", 15, "bold"), fg="white")
b1.place(x=10, y=335)
self.root.bind("<Return>", self.register_data)
img4 = Image.open(r"Images\log_btn.jpg")
img4 = img4.resize((200, 65), Image.ANTIALIAS)
self.photoimg4 = ImageTk.PhotoImage(img4)

Page 32 of 87
b1 = Button(in_frame, image=self.photoimg4,
command=self.root.destroy, borderwidth=0, cursor="hand2",
font=("Cascadia Code", 15, "bold"), fg="white")
b1.place(x=260, y=345)
img5 = Image.open(r"Images\del_btn.png")
img5 = img5.resize((200, 65), Image.ANTIALIAS)
self.photoimg5 = ImageTk.PhotoImage(img5)
b1 = Button(in_frame, image=self.photoimg5,
command=self.delete_data, borderwidth=0, cursor="hand2",
font=("Cascadia Code", 15, "bold"), fg="white")
b1.place(x=490, y=340)
def register_data(self, event=""):
if self.var_fname.get() == "" or self.var_lname.get() == "" or
self.var_contact.get() == "" or self.var_email.get() == "" or
self.var_sec_q.get() == "Select" or self.var_sec_a.get() == "" or
self.var_pass.get() == "" or self.var_con_pass.get() == "":
messagebox.showerror("ERROR!", "All fields are
required!", parent=self.root)
elif self.var_pass.get() != self.var_con_pass.get():
messagebox.showerror("ERROR!", "Password does not
match!", parent=self.root)
elif self.var_check.get() == 0:
messagebox.showerror("ERROR!", "Please agree the
agreement!", parent=self.root)
else:
try:

Page 33 of 87
my_cursor.execute("SELECT * FROM Register
WHERE Email=%s", (self.var_email.get(),))
row = my_cursor.fetchone()
if row != None:
messagebox.showerror("ERROR!", "User already
exist!", parent=self.root)
else:
my_cursor.execute("INSERT INTO Register
VALUES(%s, %s, %s, %s, %s, %s, %s)", (self.var_fname.get(),
self.var_lname.get(), self.var_contact.get(), self.var_email.get(),
self.var_sec_q.get(), self.var_sec_a.get(), self.var_pass.get()))
conn.commit()
self.reset_data()
messagebox.showinfo("SUCCESS!", "Successfully
Registered!", parent=self.root)
except Exception as e:
messagebox.showerror("ERROR!", f"ERROR: {e}",
parent=self.root)
def delete_data(self):
if self.var_email.get() == "":
messagebox.showerror("ERROR!", "Email Address is
required to delete the account!", parent=self.root)
else:
my_cursor.execute("SELECT * FROM Register WHERE
Email=%s", (self.var_email.get(),))
row = my_cursor.fetchone()
Page 34 of 87
if row == None:
messagebox.showerror("ERROR!", "User Not Found!",
parent=self.root)
else:
sure = messagebox.askyesno("DELETE!", "Are you
sure you want to delete your account!", parent=self.root)
if sure == 1:
my_cursor.execute("DELETE FROM Register
WHERE Email=%s", (self.var_email.get(),))
conn.commit()
self.reset_data()
messagebox.showinfo("SUCCESS!", "Successfully
deleted the account!", parent=self.root)
else:
pass
def reset_data(self):
self.var_fname.set("")
self.var_lname.set("")
self.var_contact.set("")
self.var_email.set("")
self.var_sec_q.set("Select")
self.var_sec_a.set("")
self.var_pass.set("")
self.var_con_pass.set("")

Page 35 of 87
class Main_Window:
def __init__(self):
self.root = Tk()
self.root.state('zoomed')
self.root.resizable(False, False)
self.root.iconbitmap(r"Images\main_logo.ico")
self.root.title("TEACHER ATTENDANCE SYSTEM")
img = Image.open(r"Images\attendance.png")
img = img.resize((500, 130), Image.ANTIALIAS)
self.photoimg = ImageTk.PhotoImage(img)
f_lbl = Label(self.root, image=self.photoimg)
f_lbl.place(x=0, y=0)
img1 = Image.open(r"Images\face_recog.png")
img1 = img1.resize((500, 130), Image.ANTIALIAS)
self.photoimg1 = ImageTk.PhotoImage(img1)
f_lbl = Label(self.root, image=self.photoimg1)
f_lbl.place(x=500, y=0)
img2 = Image.open(r"Images\school_logo.png")
img2 = img2.resize((362, 130), Image.ANTIALIAS)
self.photoimg2 = ImageTk.PhotoImage(img2)
f_lbl = Label(self.root, image=self.photoimg2)
f_lbl.place(x=1000, y=0)
img3 = Image.open(r"Images\bg.jpg")

Page 36 of 87
img3 = img3.resize((1362, 660), Image.ANTIALIAS)
self.photoimg3 = ImageTk.PhotoImage(img3)
bg_img = Label(self.root, image=self.photoimg3)
bg_img.place(x=0, y=130)
title_lbl = Label(bg_img, text="FACE RECOGNITION
ATTENDANCE SYSTEM", font=("Cascadia Code", 30, "bold"),
bg="white", fg="red")
title_lbl.place(x=0, y=0, width=1366, height=50)
def time():
string = strftime("%I:%M:%S %p")
lbl.config(text=string)
lbl.after(1000, time)
lbl = Label(title_lbl, font=("Cascadia Code", 14, "bold"),
bg="white", fg="green")
lbl.place(x=0, y=0, width=130, height=50)
time()
img4 = Image.open(r"Images\teacher.jpg")
img4 = img4.resize((170, 170), Image.ANTIALIAS)
self.photoimg4 = ImageTk.PhotoImage(img4)
b1 = Button(bg_img, image=self.photoimg4,
command=self.teacher_details, cursor="hand2")
b1.place(x=100, y=80)
b1_1 = Button(bg_img, text="TEACHER DETAILS",
command=self.teacher_details, cursor="hand2", font=("Cascadia
Code", 12, "bold"), bg="darkblue", fg="green")
Page 37 of 87
b1_1.place(x=100, y=256, width=176)
img5 = Image.open(r"Images\face_img.jpg")
img5 = img5.resize((170, 170), Image.ANTIALIAS)
self.photoimg5 = ImageTk.PhotoImage(img5)
b2 = Button(bg_img, image=self.photoimg5,
command=self.face_data, cursor="hand2")
b2.place(x=420, y=80)
b2_2 = Button(bg_img, text="FACE DETECTOR",
command=self.face_data, cursor="hand2", font=("Cascadia
Code", 12, "bold"), bg="darkblue", fg="green")
b2_2.place(x=420, y=256, width=176)
img6 = Image.open(r"Images\attend.jpg")
img6 = img6.resize((170, 170), Image.ANTIALIAS)
self.photoimg6 = ImageTk.PhotoImage(img6)
b3 = Button(bg_img, image=self.photoimg6,
command=self.attendance_data, cursor="hand2")
b3.place(x=740, y=80)
b3_3 = Button(bg_img, text="ATTENDANCE SHEET",
command=self.attendance_data, cursor="hand2",
font=("Cascadia Code", 12, "bold"), bg="darkblue", fg="green")
b3_3.place(x=740, y=256, width=176)
img7 = Image.open(r"Images\help.png")
img7 = img7.resize((170, 170), Image.ANTIALIAS)
self.photoimg7 = ImageTk.PhotoImage(img7)

Page 38 of 87
b4 = Button(bg_img, image=self.photoimg7,
command=self.help_data, cursor="hand2")
b4.place(x=1080, y=80)
b4_4 = Button(bg_img, text="HELP",
command=self.help_data, cursor="hand2", font=("Cascadia
Code", 12, "bold"), bg="darkblue", fg="green")
b4_4.place(x=1080, y=256, width=176)
img9 = Image.open(r"Images\photos.png")
img9 = img9.resize((170, 170), Image.ANTIALIAS)
self.photoimg9 = ImageTk.PhotoImage(img9)
b6 = Button(bg_img, image=self.photoimg9,
command=self.open_img, cursor="hand2")
b6.place(x=260, y=320)
b6_6 = Button(bg_img, text="PHOTOS",
command=self.open_img, cursor="hand2", font=("Cascadia
Code", 12, "bold"), bg="darkblue", fg="green")
b6_6.place(x=260, y=496, width=176)
img10 = Image.open(r"Images\graph.png")
img10 = img10.resize((170, 170), Image.ANTIALIAS)
self.photoimg10 = ImageTk.PhotoImage(img10)
b7 = Button(bg_img, image=self.photoimg10,
command=self.graph_data, cursor="hand2")
b7.place(x=580, y=320)
b7_7 = Button(bg_img, text="GRAPH",
command=self.graph_data, cursor="hand2", font=("Cascadia
Code", 12, "bold"), bg="darkblue", fg="green")
Page 39 of 87
b7_7.place(x=580, y=496, width=176)
img11 = Image.open(r"Images\exit.png")
img11 = img11.resize((170, 170), Image.ANTIALIAS)
self.photoimg11 = ImageTk.PhotoImage(img11)
b8 = Button(bg_img, image=self.photoimg11,
command=self.exit_func, cursor="hand2")
b8.place(x=910, y=320)
b8_8 = Button(bg_img, text="EXIT",
command=self.exit_func, cursor="hand2", font=("Cascadia Code",
12, "bold"), bg="darkblue", fg="green")
b8_8.place(x=910, y=496, width=176)
self.root.protocol("WM_DELETE_WINDOW", self.exit_func)
self.root.mainloop()
def exit_func(self):
self.msg = messagebox.askyesno("Attendance Mangement",
"Are you sure you want to exit?", parent=self.root)
if self.msg == 1:
self.root.destroy()
def open_img(self):
os.startfile("Data")
def teacher_details(self):
self.new_window = Toplevel(self.root)
self.app = Teacher(self.new_window)
def face_data(self):

Page 40 of 87
self.new_window = Toplevel(self.root)
self.app = Face_Recognition(self.new_window)
def attendance_data(self):
self.new_window = Toplevel(self.root)
self.app = Attendance(self.new_window)
def graph_data(self):
self.new_window = Toplevel(self.root)
self.app = Graph(self.new_window)
def help_data(self):
self.new_window = Toplevel(self.root)
self.app = Help(self.new_window)
class Teacher:
def __init__(self, root):
self.root = root
self.root.state('zoomed')
self.root.resizable(False, False)
self.root.iconbitmap(r"Images\teacher_logo.ico")
self.root.title("TEACHER DETAILS")
img = Image.open(r"Images\teach1.jpg")
img = img.resize((400, 130), Image.ANTIALIAS)
self.photoimg = ImageTk.PhotoImage(img)
f_lbl = Label(self.root, image=self.photoimg)
f_lbl.place(x=0, y=0)

Page 41 of 87
img1 = Image.open(r"Images\teach2.jpg")
img1 = img1.resize((600, 130), Image.ANTIALIAS)
self.photoimg1 = ImageTk.PhotoImage(img1)
f_lbl = Label(self.root, image=self.photoimg1)
f_lbl.place(x=400, y=0)
img2 = Image.open(r"Images\school_logo.png")
img2 = img2.resize((362, 130), Image.ANTIALIAS)
self.photoimg2 = ImageTk.PhotoImage(img2)
f_lbl = Label(self.root, image=self.photoimg2)
f_lbl.place(x=1000, y=0)
img3 = Image.open(r"Images\bg.jpg")
img3 = img3.resize((1362, 660), Image.ANTIALIAS)
self.photoimg3 = ImageTk.PhotoImage(img3)
bg_img = Label(self.root, image=self.photoimg3)
bg_img.place(x=0, y=130)
title_lbl = Label(bg_img, text="TEACHER MANAGEMENT
SYSTEM", font=("Cascadia Code", 35, "bold"), bg="white",
fg="darkgreen")
title_lbl.place(x=0, y=
0, width=1366, height=50)
main_frame = Frame(bg_img, bd=2)
main_frame.place(x=0, y=55, width=1362, height=515)
left_frame = LabelFrame(main_frame, bd=2, relief=RIDGE,
text="Teacher Details", font=("Cascadia Code", 12, "bold"))

Page 42 of 87
left_frame.place(x=10, y=5, width=650, height=500)
dep_label = Label(left_frame, text="Department:",
font=("Cascadia Code", 12, "bold"), bg="white")
dep_label.grid(row=0, column=0, pady=10, sticky=W)
self.var_dep = StringVar()
dep_combo = ttk.Combobox(left_frame,
textvariable=self.var_dep, font=("Cascadia Code", 12, "bold"),
width=18, state="readonly")
dep_combo["values"] = ("Select Department", "Computer",
"IT", "Civil", "Mechanical")
dep_combo.current(0)
dep_combo.grid(row=0, column=1, padx=5, pady=10,
sticky=W)
cat_label = Label(left_frame, text="Category:",
font=("Cascadia Code", 12, "bold"), bg="white")
cat_label.grid(row=0, column=2, pady=10, sticky=W)
self.var_cat = StringVar()
cat_combo = ttk.Combobox(left_frame,
textvariable=self.var_cat, font=("Cascadia Code", 12, "bold"),
width=15, state="readonly")
cat_combo["values"] = ("Select Category", "PGT", "TGT",
"PRT")
cat_combo.current(0)
cat_combo.grid(row=0, column=3, padx=5, pady=10,
sticky=W)

Page 43 of 87
year_label = Label(left_frame, text="Year Of Joining:",
font=("Cascadia Code", 12, "bold"), bg="white")
year_label.grid(row=1, column=0, pady=10, sticky=W)
self.var_year = StringVar()
year_combo = ttk.Combobox(left_frame,
textvariable=self.var_year, font=("Cascadia Code", 12, "bold"),
width=18, state="readonly")
year_combo["values"] = ("Select Year", "1990-1998", "1999-
2007", "2008-2016", "2017-2021")
year_combo.current(0)
year_combo.grid(row=1, column=1, padx=5, pady=10,
sticky=W)
semester_label = Label(left_frame, text="Semester:",
font=("Cascadia Code", 12, "bold"), bg="white")
semester_label.grid(row=1, column=2, pady=10, sticky=W)
self.var_semester = StringVar()
semester_combo = ttk.Combobox(left_frame,
textvariable=self.var_semester, font=("Cascadia Code", 12,
"bold"), width=15, state="readonly")
semester_combo["values"] = ("Select Semester", "Semester-
1", "Semester-2")
semester_combo.current(0)
semester_combo.grid(row=1, column=3, padx=5, pady=10,
sticky=W)
teacher_id_label = Label(left_frame, text="Teacher ID:",
font=("Cascadia Code", 12, "bold"), bg="white")

Page 44 of 87
teacher_id_label.grid(row=2, column=0, pady=10, sticky=W)
self.var_teach_id = StringVar()
teacher_id_entry = ttk.Entry(left_frame,
textvariable=self.var_teach_id, width=20, font=("Cascadia Code",
12, "bold"))
teacher_id_entry.grid(row=2, column=1, padx=5, sticky=W)
teacher_name_label = Label(left_frame, text="Teacher
Name:", font=("Cascadia Code", 12, "bold"), bg="white")
teacher_name_label.grid(row=2, column=2, pady=10,
sticky=W)
self.var_teach_name = StringVar()
teacher_name_entry = ttk.Entry(left_frame,
textvariable=self.var_teach_name, width=16, font=("Cascadia
Code", 12, "bold"))
teacher_name_entry.grid(row=2, column=3, padx=5,
sticky=W)
ct_label = Label(left_frame, text="Class Teacher:",
font=("Cascadia Code", 12, "bold"), bg="white")
ct_label.grid(row=3, column=0, pady=10, sticky=W)
self.var_ct = StringVar()
ct_combo = ttk.Combobox(left_frame,
textvariable=self.var_ct, font=("Cascadia Code", 12, "bold"),
width=18, state="readonly")
ct_combo["values"] = ("Select Class", "None", "I", "II", "III",
"IV", "V", "VI", "VII", "VIII", "IX", "X", "XI", "XII")
ct_combo.current(0)

Page 45 of 87
ct_combo.grid(row=3, column=1, padx=5, pady=10,
sticky=W)
table_no_label = Label(left_frame, text="Table No:",
font=("Cascadia Code", 12, "bold"), bg="white")
table_no_label.grid(row=3, column=2, pady=10, sticky=W)
self.var_table_no = StringVar()
table_no_entry = ttk.Entry(left_frame,
textvariable=self.var_table_no, width=16, font=("Cascadia Code",
12, "bold"))
table_no_entry.grid(row=3, column=3, padx=5, sticky=W)
gender_label = Label(left_frame, text="Gender:",
font=("Cascadia Code", 12, "bold"), bg="white")
gender_label.grid(row=4, column=0, pady=10, sticky=W)
self.var_gender = StringVar()
gender_combo = ttk.Combobox(left_frame,
textvariable=self.var_gender, font=("Cascadia Code", 12, "bold"),
width=18, state="readonly")
gender_combo["values"] = ("Select Gender", "Male",
"Female", "Other")
gender_combo.current(0)
gender_combo.grid(row=4, column=1, padx=5, pady=10,
sticky=W)
dob_label = Label(left_frame, text="DOB:", font=("Cascadia
Code", 12, "bold"), bg="white")
dob_label.grid(row=4, column=2, pady=10, sticky=W)
self.var_dob = StringVar()

Page 46 of 87
dob_entry = DateEntry(left_frame, textvariable=self.var_dob,
date_pattern="dd/mm/yyyy", width=15, font=("Cascadia Code",
12, "bold"), state="readonly")
dob_entry.grid(row=4, column=3, padx=5, sticky=W)
self.var_dob.set("12/12/2000")
email_label = Label(left_frame, text="Email:",
font=("Cascadia Code", 12, "bold"), bg="white")
email_label.grid(row=5, column=0, pady=10, sticky=W)
self.var_email = StringVar()
email_entry = ttk.Entry(left_frame,
textvariable=self.var_email, width=20, font=("Cascadia Code", 12,
"bold"))
email_entry.grid(row=5, column=1, padx=5, sticky=W)
phone_no_label = Label(left_frame, text="Phone No:",
font=("Cascadia Code", 12, "bold"), bg="white")
phone_no_label.grid(row=5, column=2, pady=10, sticky=W)
self.var_phone = StringVar()
phone_no_entry = ttk.Entry(left_frame,
textvariable=self.var_phone, width=16, font=("Cascadia Code",
12, "bold"))
phone_no_entry.grid(row=5, column=3, padx=5, sticky=W)
address_label = Label(left_frame, text="Address:",
font=("Cascadia Code", 12, "bold"), bg="white")
address_label.grid(row=6, column=0, pady=10, sticky=W)
self.var_address = StringVar()

Page 47 of 87
address_entry = ttk.Entry(left_frame,
textvariable=self.var_address, width=20, font=("Cascadia Code",
12, "bold"))
address_entry.grid(row=6, column=1, padx=5, sticky=W)
staff_label = Label(left_frame, text="Staff Room No.:",
font=("Cascadia Code", 12, "bold"), bg="white")
staff_label.grid(row=6, column=2, pady=10, sticky=W)
self.var_staff = StringVar()
staff_combo = ttk.Combobox(left_frame,
textvariable=self.var_staff, font=("Cascadia Code", 12, "bold"),
width=15, state="readonly")
staff_combo["values"] = ("Select No.", "1", "2", "3")
staff_combo.current(0)
staff_combo.grid(row=6, column=3, padx=5, pady=10,
sticky=W)
self.var_check = StringVar()
check_btn = Checkbutton(left_frame, text="Take Photo
Sample", variable=self.var_check, font=("Cascadia Code", 15,
"bold"), onvalue="Yes", offvalue="No")
check_btn.place(x=10, y=320)
btn_frame = Frame(left_frame, bd=2, relief=RIDGE)
btn_frame.place(x=12, y=360, width=619, height=50)
save_btn = Button(btn_frame, text="SAVE",
command=self.add_data, cursor="hand2", width=16,
font=("Cascadia Code", 12, "bold"), bg="blue", fg="white",
height=2)

Page 48 of 87
save_btn.grid(row=0, column=0)
self.root.bind("<Return>", self.add_data)
update_btn = Button(btn_frame, text="UPDATE",
command=self.update_data, cursor="hand2", width=16,
font=("Cascadia Code", 12, "bold"), bg="blue", fg="white",
height=2)
update_btn.grid(row=0, column=1)
del_btn = Button(btn_frame, text="DELETE",
command=self.delete_data, cursor="hand2", width=16,
font=("Cascadia Code", 12, "bold"), bg="blue", fg="white",
height=2)
del_btn.grid(row=0, column=2)
reset_btn = Button(btn_frame, text="RESET",
command=self.reset_data, cursor="hand2", width=16,
font=("Cascadia Code", 12, "bold"), bg="blue", fg="white",
height=2)
reset_btn.grid(row=0, column=3)
update_photo_btn = Button(main_frame, text="TAKE OR
UPDATE PHOTO SAMPLE", command=self.update_dataset,
cursor="hand2", width=37, font=("Cascadia Code", 12, "bold"),
bg="blue", fg="white", height=2)
update_photo_btn.place(x=150, y=450, width=340,
height=50)
right_frame = LabelFrame(main_frame, bd=2, relief=RIDGE,
text="Teacher Information", font=("Cascadia Code", 12, "bold"))
right_frame.place(x=680, y=5, width=650, height=500)
img_right = Image.open(r"Images\search.png")

Page 49 of 87
img_right = img_right.resize((305, 130), Image.ANTIALIAS)
self.photoimg_right = ImageTk.PhotoImage(img_right)
f_lbl = Label(right_frame, image=self.photoimg_right)
f_lbl.place(x=5, y=0)
other_img = Image.open(r"Images\search2.jpg")
other_img = other_img.resize((315, 130), Image.ANTIALIAS)
self.photoother_img = ImageTk.PhotoImage(other_img)
f_lbl = Label(right_frame, image=self.photoother_img)
f_lbl.place(x=315, y=0)
search_frame = LabelFrame(right_frame, bd=2,
relief=RIDGE, text="Search System", font=("Cascadia Code", 12,
"bold"))
search_frame.place(x=5, y=130, width=630, height=70)
search_label = Label(search_frame, text="Search By:",
font=("Cascadia Code", 12, "bold"), bg="red", fg="white")
search_label.grid(row=0, column=0, padx=15, pady=10,
sticky=W)
self.var_search_by = StringVar()
search_combo = ttk.Combobox(search_frame,
font=("Cascadia Code", 12, "bold"),
textvariable=self.var_search_by, width=15, state="readonly")
search_combo["values"] = ("Select", "Teacher_Name",
"Department")
search_combo.current(0)

Page 50 of 87
search_combo.grid(row=0, column=1, padx=5, pady=10,
sticky=W)
self.var_search_data = StringVar()
search_entry = ttk.Entry(search_frame,
textvariable=self.var_search_data, width=17, font=("Cascadia
Code", 12, "bold"))
search_entry.grid(row=0, column=2, padx=10, sticky=W)
search_btn = Button(search_frame, text="SEARCH",
command=self.search_data, cursor="hand2", width=7,
font=("Cascadia Code", 9, "bold"), bg="blue", fg="white")
search_btn.grid(row=0, column=3, padx=2)
show_all_btn = Button(search_frame, text="SHOW ALL",
command=self.fetch_data, cursor="hand2", width=9,
font=("Cascadia Code", 9, "bold"), bg="blue", fg="white")
show_all_btn.grid(row=0, column=4, padx=2)
table_frame = Frame(right_frame, bd=2, relief=RIDGE)
table_frame.place(x=5, y=205, width=634, height=265)
scroll_x = ttk.Scrollbar(table_frame, orient=HORIZONTAL)
scroll_y = ttk.Scrollbar(table_frame, orient=VERTICAL)
self.teacher_table = ttk.Treeview(table_frame,
columns=("dep", "category", "year", "sem", "id", "name",
"class_teacher", "table_no", "gender", "dob", "email", "phone",
"address", "staff", "photo"), xscrollcommand=scroll_x.set,
yscrollcommand=scroll_y.set)
scroll_x.pack(side=BOTTOM, fill=X)
scroll_y.pack(side=RIGHT, fill=Y)

Page 51 of 87
scroll_x.config(command=self.teacher_table.xview)
scroll_y.config(command=self.teacher_table.yview)
self.teacher_table.heading("dep", text="Department")
self.teacher_table.heading("category", text="Category")
self.teacher_table.heading("year", text="Year")
self.teacher_table.heading("sem", text="Semester")
self.teacher_table.heading("id", text="Teacher ID")
self.teacher_table.heading("name", text="Name")
self.teacher_table.heading("class_teacher", text="Class
Teacher")
self.teacher_table.heading("table_no", text="Table No.")
self.teacher_table.heading("gender", text="Gender")
self.teacher_table.heading("dob", text="DOB")
self.teacher_table.heading("email", text="Email")
self.teacher_table.heading("phone", text="Phone")
self.teacher_table.heading("address", text="Address")
self.teacher_table.heading("staff", text="Staff Room No.")
self.teacher_table.heading("photo", text="Photo Sample")
self.teacher_table["show"] = "headings"
self.teacher_table.column("dep", width=100,
anchor=CENTER)
self.teacher_table.column("category", width=100,
anchor=CENTER)

Page 52 of 87
self.teacher_table.column("year", width=100,
anchor=CENTER)
self.teacher_table.column("sem", width=100,
anchor=CENTER)
self.teacher_table.column("id", width=100, anchor=CENTER)
self.teacher_table.column("name", width=100,
anchor=CENTER)
self.teacher_table.column("class_teacher", width=100,
anchor=CENTER)
self.teacher_table.column("table_no", width=100,
anchor=CENTER)
self.teacher_table.column("gender", width=100,
anchor=CENTER)
self.teacher_table.column("dob", width=100,
anchor=CENTER)
self.teacher_table.column("email", width=100,
anchor=CENTER)
self.teacher_table.column("phone", width=100,
anchor=CENTER)
self.teacher_table.column("address", width=100,
anchor=CENTER)
self.teacher_table.column("staff", width=100,
anchor=CENTER)
self.teacher_table.column("photo", width=100,
anchor=CENTER)
self.teacher_table.pack(fill=BOTH, expand=1)
self.teacher_table.bind("<ButtonRelease>", self.get_cursor)
Page 53 of 87
self.fetch_data()
def add_data(self, event=""):
if self.var_dep.get() == "Select Department" or
self.var_cat.get() == "Select Category" or self.var_year.get() ==
"Select Year" or self.var_semester.get() == "Select Semester" or
self.var_teach_id.get() == "" or self.var_teach_name.get() == "" or
self.var_ct.get() == "Select Class" or self.var_table_no.get() == ""
or self.var_gender.get() == "Select Gender" or self.var_dob.get()
== "" or self.var_email.get() == "" or self.var_phone.get() == "" or
self.var_address.get() == "" or self.var_staff.get() == "Select No.":
messagebox.showerror("ERROR!", "All fields are
required!", parent=self.root)
else:
try:
my_cursor.execute(f'SELECT * FROM Teacher
WHERE Teacher_ID="{self.var_teach_id.get()}"')
data = my_cursor.fetchone()
if data == None and self.var_check.get() == "Yes":
self.generate_dataset()
my_cursor.execute("INSERT INTO Teacher
VALUES(%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s,
%s, %s, %s)", (self.var_dep.get(), self.var_cat.get(),
self.var_year.get(), self.var_semester.get(),
self.var_teach_id.get(), self.var_teach_name.get(),
self.var_ct.get(), self.var_table_no.get(), self.var_gender.get(),
self.var_dob.get(), self.var_email.get(), self.var_phone.get(),
self.var_address.get(), self.var_staff.get(), self.var_check.get()))
conn.commit()
Page 54 of 87
self.fetch_data()
self.reset_data()
messagebox.showinfo("SUCCESS!", "Teacher details
has been added successfully!", parent=self.root)
except Exception as e:
messagebox.showerror("ERROR!", f"ERROR: {e}",
parent=self.root)
def fetch_data(self):
my_cursor.execute("SELECT * FROM Teacher")
data = my_cursor.fetchall()
if len(data) != 0:

self.teacher_table.delete(*self.teacher_table.get_children())
for n, i in enumerate(data):
if n % 2 == 0:
self.teacher_table.insert("", END, values=i,
tags=("evenrow", ))
else:
self.teacher_table.insert("", END, values=i,
tags=("oddrow", ))
conn.commit()
else:
for item in self.teacher_table.get_children():
self.teacher_table.delete(item)
def get_cursor(self, event=""):
Page 55 of 87
cursor_focus = self.teacher_table.focus()
content = self.teacher_table.item(cursor_focus)
data = content["values"]
if len(data) > 0:
self.var_dep.set(data[0])
self.var_cat.set(data[1])
self.var_year.set(data[2])
self.var_semester.set(data[3])
self.var_teach_id.set(data[4])
self.var_teach_name.set(data[5])
self.var_ct.set(data[6])
self.var_table_no.set(data[7])
self.var_gender.set(data[8])
self.var_dob.set(data[9])
self.var_email.set(data[10])
self.var_phone.set(data[11])
self.var_address.set(data[12])
self.var_staff.set(data[13])
self.var_check.set(data[14])
def update_data(self):
if self.var_dep.get() == "Select Department" or
self.var_cat.get() == "Select Category" or self.var_year.get() ==
"Select Year" or self.var_semester.get() == "Select Semester" or
self.var_teach_id.get() == "" or self.var_teach_name.get() == "" or

Page 56 of 87
self.var_ct.get() == "Select Class" or self.var_table_no.get() == ""
or self.var_gender.get() == "Select Gender" or self.var_dob.get()
== "" or self.var_email.get() == "" or self.var_phone.get() == "" or
self.var_address.get() == "" or self.var_staff.get() == "Select No.":
messagebox.showerror("ERROR!", "All fields are
required!", parent=self.root)
else:
try:
update = messagebox.askyesno("UPDATE!", "Do you
want to update this teacher details?", parent=self.root)
if update == 1:
my_cursor.execute("UPDATE Teacher SET
Department=%s, Category=%s, Year=%s, Semester=%s,
Teacher_Name=%s, Class_Teacher=%s, Table_No=%s,
Gender=%s, DOB=%s, Email=%s, Phone=%s, Address=%s,
Staff_Room_No=%s WHERE Teacher_ID=%s",
(self.var_dep.get(), self.var_cat.get(), self.var_year.get(),
self.var_semester.get(), self.var_teach_name.get(),
self.var_ct.get(), self.var_table_no.get(), self.var_gender.get(),
self.var_dob.get(), self.var_email.get(), self.var_phone.get(),
self.var_address.get(), self.var_staff.get(),
self.var_teach_id.get()))
conn.commit()
self.fetch_data()
self.reset_data()
messagebox.showinfo("SUCCESS!", "Teacher
details successfully updated!", parent=self.root)
else:
Page 57 of 87
pass
except Exception as e:
messagebox.showerror("ERROR!", f"ERROR: {e}",
parent=self.root)
def delete_data(self):
if self.var_dep.get() == "Select Department" or
self.var_cat.get() == "Select Category" or self.var_year.get() ==
"Select Year" or self.var_semester.get() == "Select Semester" or
self.var_teach_id.get() == "" or self.var_teach_name.get() == "" or
self.var_ct.get() == "Select Class" or self.var_table_no.get() == ""
or self.var_gender.get() == "Select Gender" or self.var_dob.get()
== "" or self.var_email.get() == "" or self.var_phone.get() == "" or
self.var_address.get() == "" or self.var_staff.get() == "Select No.":
messagebox.showerror("ERROR!", "All details are
required!", parent=self.root)
else:
try:
delete = messagebox.askyesno("Teacher Deletion",
"Do you want to delete this teacher details?", parent=self.root)
if delete == 1:
my_cursor.execute("DELETE FROM Teacher
WHERE Teacher_ID=%s", (self.var_teach_id.get(),))
self.fetch_data()
conn.commit()
os.remove(f"Data\\{self.var_teach_name.get()}.jpg")
self.reset_data()

Page 58 of 87
messagebox.showinfo("DELETE!", "Successfully
deleted teacher details", parent=self.root)
else:
pass
except Exception as e:
messagebox.showerror("ERROR!", f"ERROR: {e}",
parent=self.root)
def reset_data(self):
self.var_dep.set("Select Department")
self.var_cat.set("Select Category")
self.var_year.set("Select Year")
self.var_semester.set("Select Semester")
self.var_teach_id.set("")
self.var_teach_name.set("")
self.var_ct.set("Select Class")
self.var_table_no.set("")
self.var_gender.set("Select Gender")
self.var_dob.set("12/12/00")
self.var_email.set("")
self.var_phone.set("")
self.var_address.set("")
self.var_staff.set("Select No.")
self.var_check.set("No")
def generate_dataset(self):
Page 59 of 87
if self.var_dep.get() == "Select Department" or
self.var_cat.get() == "Select Category" or self.var_year.get() ==
"Select Year" or self.var_semester.get() == "Select Semester" or
self.var_teach_id.get() == "" or self.var_teach_name.get() == "" or
self.var_ct.get() == "Select Class" or self.var_table_no.get() == ""
or self.var_gender.get() == "Select Gender" or self.var_dob.get()
== "" or self.var_email.get() == "" or self.var_phone.get() == "" or
self.var_address.get() == "" or self.var_staff.get() == "Select No.":
messagebox.showerror("ERROR!", "All fields are
required!", parent=self.root)
else:
try:
name = self.var_teach_name.get()
my_cursor.execute(f'UPDATE Teacher SET
Photo_Sample="Yes" WHERE Teacher_Name="{name}"')
conn.commit()
self.fetch_data()
cap = cv2.VideoCapture(0)
while True:
_, img = cap.read()
cv2.imshow('PRESS SPACE TO TAKE A PHOTO',
img)
k = cv2.waitKey(1)
if k%256 == 32:
file_name_path = f"Data/{name}.jpg"
cv2.imwrite(file_name_path, img)

Page 60 of 87
cap.release()
cv2.destroyAllWindows()
break
except Exception as e:
messagebox.showerror("ERROR!", f"ERROR: {e}",
parent=self.root)
def update_dataset(self):
if self.var_dep.get() == "Select Department" or
self.var_cat.get() == "Select Category" or self.var_year.get() ==
"Select Year" or self.var_semester.get() == "Select Semester" or
self.var_teach_id.get() == "" or self.var_teach_name.get() == "" or
self.var_ct.get() == "Select Class" or self.var_table_no.get() == ""
or self.var_gender.get() == "Select Gender" or self.var_dob.get()
== "" or self.var_email.get() == "" or self.var_phone.get() == "" or
self.var_address.get() == "" or self.var_staff.get() == "Select No.":
messagebox.showerror("ERROR!", "All fields are
required!", parent=self.root)
else:
try:
if os.path.exists(f"Data\\User.
{self.var_teach_name.get()}.jpg"):
os.remove(f"Data\\{self.var_teach_name.get()}.jpg")
self.generate_dataset()
messagebox.showinfo("SUCCESS!", "Data Updated!",
parent=self.root)
self.reset_data()

Page 61 of 87
except Exception as e:
messagebox.showerror("ERROR!", f"ERROR: {e}",
parent=self.root)
def search_data(self):
if self.var_search_by.get() == "Select" or
self.var_search_data.get() == "":
messagebox.showerror("ERROR!", "Entry Field
Required!", parent=self.root)
else:
try:
my_cursor.execute(f'SELECT * FROM Teacher
WHERE
{self.var_search_by.get()}="{self.var_search_data.get()}"')
data = my_cursor.fetchall()
if len(data) != 0:

self.teacher_table.delete(*self.teacher_table.get_children())
for i in data:
self.teacher_table.insert("", END, values=i)
else:
for item in self.teacher_table.get_children():
self.teacher_table.delete(item)
conn.commit()
except Exception as e:

Page 62 of 87
messagebox.showerror("ERROR!", f"ERROR: {e}",
parent=self.root)
class Face_Recognition:
def __init__(self, root):
self.root = root
self.root.state('zoomed')
self.root.resizable(False, False)
self.root.iconbitmap(r"Images\face_recog_logo.ico")
self.root.title("FACE RECOGNITION SYSTEM")
title_lbl = Label(self.root, text="FACE RECOGNITION",
font=("Cascadia Code", 35, "bold"), bg="white", fg="green")
title_lbl.place(x=0, y=0, width=1366, height=50)
img1 = Image.open(r"Images\face1.jpg")
img1 = img1.resize((681, 700), Image.ANTIALIAS)
self.photoimg1 = ImageTk.PhotoImage(img1)
f_lbl = Label(self.root, image=self.photoimg1)
f_lbl.place(x=0, y=48)
img2 = Image.open(r"Images\phone.jpg")
img2 = img2.resize((681, 700), Image.ANTIALIAS)
self.photoimg2 = ImageTk.PhotoImage(img2)
f_lbl = Label(self.root, image=self.photoimg2)
f_lbl.place(x=682, y=48)
img3 = Image.open(r"Images\attend2.jpg")
img3 = img3.resize((300, 300), Image.ANTIALIAS)
Page 63 of 87
self.photoimg3 = ImageTk.PhotoImage(img3)
f_lbl2 = Label(self.root, image=self.photoimg3)
f_lbl2.place(x=870, y=200)
button = Button(f_lbl, text="FACE
RECOGNITION",command=self.face_recog, cursor="hand2",
font=("Cascadia Code", 30, "bold"), bg="green", fg="white")
button.place(x=155, y=500, width=380, height=100)
self.root.bind("<Return>", self.face_recog)
self.today = datetime.now().strftime("%d-%m-%Y")
if not os.path.exists(f"Attendance\\{self.today}.csv"):
with open(f"Attendance\\{self.today}.csv", "w") as f:
f.writelines("Teacher ID,Teacher
Name,Time,Date,Attendance")
self.root.protocol("WM_DELETE_WINDOW", self.exit_func)
def exit_func(self):
y_n = messagebox.askyesno("WARNING!", "Are you sure
you want to close this window?\nThe remaining teachers will be
marked 'Absent'!", parent=self.root)
if y_n == 1:
my_cursor.execute("SELECT Teacher_ID FROM
Teacher")
data = my_cursor.fetchall()
with open(f"Attendance\\{self.today}.csv", "r+") as f:
my_data = f.readlines()
id_list = [line.split(",")[0] for line in my_data]
Page 64 of 87
for i in data:
if str(i[0]) not in id_list:
my_cursor.execute("SELECT Teacher_ID,
Teacher_Name FROM Teacher WHERE Teacher_ID=" + str(i[0]))
info = my_cursor.fetchone()
f.writelines(f"\n{info[0]},{info[1]},-,
{self.today},Absent")
conn.commit()
self.root.destroy()
def mark_attendance(self, name):
my_cursor.execute("SELECT Teacher_ID FROM Teacher
WHERE Teacher_Name=%s", (name, ))
i = my_cursor.fetchone()[0]
conn.commit()
with open(f"Attendance\\{self.today}.csv", "r+") as f:
my_data = f.readlines()
id_list = [line.split(",")[0] for line in my_data]
if str(i) not in id_list:
now = datetime.now()
cur_time = now.strftime("%H:%M:%S")
f.writelines(f"\n{i},{name},{cur_time},
{self.today},Present")
def face_recog(self, event=""):
try:

Page 65 of 87
def findEncodings(images):
encode_list = []
for img in images:
img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
encode = face_recognition.face_encodings(img)[0]
encode_list.append(encode)
return encode_list
path = "Data"
images = []
class_names = []
my_list = os.listdir(path)
for cl in my_list:
cur_img = cv2.imread(f"{path}\\{cl}")
images.append(cur_img)
class_names.append(os.path.splitext(cl)[0])
encode_list_known = findEncodings(images)
cap = cv2.VideoCapture(0)
while True:
success, img = cap.read()
img_s = cv2.resize(img, (0, 0), None, 0.25, 0.25)
img_s = cv2.cvtColor(img_s, cv2.COLOR_BGR2RGB)
faces_cur_frame =
face_recognition.face_locations(img_s)

Page 66 of 87
encodes_cur_frame =
face_recognition.face_encodings(img_s, faces_cur_frame)
for encodeFace, faceLoc in zip(encodes_cur_frame,
faces_cur_frame):
matches =
face_recognition.compare_faces(encode_list_known,
encodeFace)
face_dis =
face_recognition.face_distance(encode_list_known, encodeFace)
match_index = np.argmin(face_dis)
if matches[match_index]:
name = class_names[match_index]
y1, x2, y2, x1 = faceLoc
y1, x2, y2, x1 = y1*4, x2*4, y2*4, x1*4
cv2.rectangle(img, (x1, y1), (x2, y2), (0, 255, 0), 2)
cv2.rectangle(img, (x1, y2-35), (x2, y2), (0, 255, 0),
cv2.FILLED)
cv2.putText(img, name, (x1+6, y2-6),
cv2.FONT_HERSHEY_COMPLEX, 1, (255, 255, 255), 2)
self.mark_attendance(name)
else:
name = "Unknown"
y1, x2, y2, x1 = faceLoc
y1, x2, y2, x1 = y1*4, x2*4, y2*4, x1*4
cv2.rectangle(img, (x1, y1), (x2, y2), (0, 0, 255), 2)

Page 67 of 87
cv2.rectangle(img, (x1, y2-35), (x2, y2), (0, 0, 255),
cv2.FILLED)
cv2.putText(img, name, (x1+6, y2-6),
cv2.FONT_HERSHEY_COMPLEX, 1, (255, 255, 255), 2)
cv2.imshow("Webcam", img)
if cv2.waitKey(1) == 13:
break
cap.release()
cv2.destroyAllWindows()
except Exception as e:
messagebox.showerror("ERROR!", f"ERROR: {e}",
parent=self.root)
class Attendance:
def __init__(self, root):
self.root = root
self.root.state('zoomed')
self.root.resizable(False, False)
self.root.iconbitmap(r"Images\attend_logo.ico")
self.root.title("ATTENDANCE SHEET")
img = Image.open(r"Images\attend3.jpg")
img=img.resize((500, 130), Image.ANTIALIAS)
self.photoimg = ImageTk.PhotoImage(img)
f_lbl = Label(self.root, image=self.photoimg)
f_lbl.place(x=0, y=0)

Page 68 of 87
img1 = Image.open(r"Images\attendance.png")
img1=img1.resize((500, 130), Image.ANTIALIAS)
self.photoimg1 = ImageTk.PhotoImage(img1)
f_lbl = Label(self.root, image=self.photoimg1)
f_lbl.place(x=500, y=0)
img2 = Image.open(r"Images\school_logo.png")
img2=img2.resize((300, 130), Image.ANTIALIAS)
self.photoimg2 = ImageTk.PhotoImage(img2)
f_lbl = Label(self.root, image=self.photoimg2)
f_lbl.place(x=1020, y=0)
img3 = Image.open(r"Images\bg.jpg")
img3=img3.resize((1362, 660), Image.ANTIALIAS)
self.photoimg3 = ImageTk.PhotoImage(img3)
bg_img = Label(self.root, image=self.photoimg3)
bg_img.place(x=0, y=130)
title_lbl = Label(bg_img, text="ATTENDANCE SHEET",
font=("Cascadia Code", 35, "bold"), bg="white", fg="darkgreen")
title_lbl.place(x=0, y=0, width=1366, height=50)
select_date_label = Label(self.root, text="Select Date:",
font=("Cascadia Code", 12, "bold"), bg="red", fg="white")
select_date_label.place(x=600, y=183)
self.var_attendance_date = StringVar()

Page 69 of 87
attendance_date= ttk.Combobox(self.root, font=("Cascadia
Code", 12, "bold"), textvariable=self.var_attendance_date,
width=15, state="readonly")
if len(os.listdir("Attendance")) > 0:
attendance_date["values"] = [i.split(".")[0] for i in
os.listdir("Attendance")]
attendance_date.current(0)
attendance_date.place(x=575, y=215)
show_btn = Button(self.root, text="SHOW",
command=self.attendance_file, cursor="hand2", width=7,
font=("Cascadia Code", 9, "bold"), bg="cyan", fg="red")
show_btn.place(x=620,y=250)
table_frame = Frame(self.root, bd=2, relief=RIDGE)
table_frame.place(x=0, y=290, width=1362, height=450)
scroll_x = ttk.Scrollbar(table_frame, orient=HORIZONTAL)
scroll_y = ttk.Scrollbar(table_frame, orient=VERTICAL)
self.attendance_table = ttk.Treeview(table_frame,
columns=("id", "name", "time", "date", "attendance"),
xscrollcommand=scroll_x.set, yscrollcommand=scroll_y.set)
scroll_x.pack(side=BOTTOM, fill=X)
scroll_y.pack(side=RIGHT, fill=Y)
scroll_x.config(command=self.attendance_table.xview)
scroll_y.config(command=self.attendance_table.yview)
self.attendance_table.heading("id", text="Teacher ID")

Page 70 of 87
self.attendance_table.heading("name", text="Teacher
Name")
self.attendance_table.heading("time", text="Time")
self.attendance_table.heading("date", text="Date")
self.attendance_table.heading("attendance",
text="Attendance")
self.attendance_table["show"] = "headings"
self.attendance_table.column("id", width=100,
anchor=CENTER)
self.attendance_table.column("name", width=100,
anchor=CENTER)
self.attendance_table.column("time", width=100,
anchor=CENTER)
self.attendance_table.column("date", width=100,
anchor=CENTER)
self.attendance_table.column("attendance", width=100,
anchor=CENTER)
self.attendance_table.pack(fill=BOTH, expand=1)
def fetch_data(self, rows):

self.attendance_table.delete(*self.attendance_table.get_children()
)
for i in rows:
self.attendance_table.insert("", END, values=i)
def attendance_file(self):
try:

Page 71 of 87
with open(f"Attendance\\
{self.var_attendance_date.get()}.csv") as my_file:
my_file.seek(46)
csv_read = csv.reader(my_file, delimiter=",")
my_data = [i for i in csv_read]
self.fetch_data(my_data)
except Exception as e:
messagebox.showerror("ERROR!", f"ERROR: {e}",
parent=self.root)
class Help:
def __init__(self, root):
self.root = root
self.root.state('zoomed')
self.root.resizable(False, False)
self.root.iconbitmap(r"Images\help_logo.ico")
self.root.title("HELP")
img1 = Image.open(r"Images\bg.jpg")
img1 = img1.resize((1362, 766), Image.ANTIALIAS)
self.photoimg1 = ImageTk.PhotoImage(img1)
f_lbl = Label(self.root, image=self.photoimg1)
f_lbl.place(x=0, y=0)
img2 = Image.open(r"Images\help_win.png")
img2 = img2.resize((650, 766), Image.ANTIALIAS)
self.photoimg2 = ImageTk.PhotoImage(img2)
Page 72 of 87
f_lbl = Label(self.root, image=self.photoimg2)
f_lbl.place(x=0, y=0)
img3 = Image.open(r"Images\school_logo.png")
img3 = img3.resize((150, 150), Image.ANTIALIAS)
self.photoimg3 = ImageTk.PhotoImage(img3)
f_lbl = Label(self.root, image=self.photoimg3)
f_lbl.place(x=920, y=20)
main_frame = LabelFrame(self.root, bd=2, relief=SUNKEN,
text="DETAILS", font=("Cascadia Code", 12, "bold"))
main_frame.place(x=750, y=190, width=500, height=500)
name_label = Label(main_frame, text="Name:",
font=("Cascadia Code", 12, "bold"), bg="white")
name_label.grid(row=0, column=0, pady=10, sticky=W)
self.var_name = StringVar()
name_entry = ttk.Entry(main_frame, width=20,
textvariable=self.var_name, font=("Cascadia Code", 12, "bold"))
name_entry.grid(row=0, column=1, padx=5, sticky=W)
name_entry.focus()
email_label = Label(main_frame, text="Email:",
font=("Cascadia Code", 12, "bold"), bg="white")
email_label.grid(row=1, column=0, pady=10, sticky=W)
self.var_email = StringVar()
email_entry = ttk.Entry(main_frame, width=20,
textvariable=self.var_email, font=("Cascadia Code", 12, "bold"))

Page 73 of 87
email_entry.grid(row=1, column=1, padx=5, sticky=W)
contact_label = Label(main_frame, text="Contact No.:",
font=("Cascadia Code", 12, "bold"), bg="white")
contact_label.grid(row=2, column=0, pady=10, sticky=W)
self.var_contact = StringVar()
contact_entry = ttk.Entry(main_frame, width=20,
textvariable=self.var_contact, font=("Cascadia Code", 12, "bold"))
contact_entry.grid(row=2, column=1, padx=5, sticky=W)
issue_label = Label(main_frame, text="Issue:",
font=("Cascadia Code", 12, "bold"), bg="white")
issue_label.grid(row=3, column=0, pady=10, sticky=W)
self.issue_entry = Text(main_frame, width=50, height=11,
font=("Cascadia Code", 12, "bold"))
self.issue_entry.grid(row=4, column=0, padx=5, sticky=W,
columnspan=3)
btn = Button(main_frame, text="SEND", cursor="hand2",
command=self.save_info, font=("Cascadia Code", 11, "bold"),
bg="darkblue", fg="green")
btn.grid(row=9, column=1, pady=7)
self.root.bind("<Return>", self.save_info)
def save_info(self, event=""):
if self.var_name.get() == "" or self.var_email.get() == "" or
self.var_contact.get() == "" or len(self.issue_entry.get("1.0",
END)) <= 1:
messagebox.showerror("ERROR!", "All fields are
required!", parent=self.root)

Page 74 of 87
else:
try:
my_cursor.execute("INSERT INTO Issues(Name,
Email, Contact_No, Issue) VALUES(%s, %s, %s, %s)",
(self.var_name.get(), self.var_email.get(), self.var_contact.get(),
self.issue_entry.get("1.0", END)))
conn.commit()
self.reset_data()
messagebox.showinfo("SUCCESS!", "We will try our
best to solve the issue!", parent=self.root)
except Exception as e:
messagebox.showerror("ERROR!", f"ERROR: {e}",
parent=self.root)
def reset_data(self):
self.var_name.set("")
self.var_email.set("")
self.var_contact.set("")
self.issue_entry.delete("1.0", END)
class Graph:
def __init__(self, root):
self.root = root
self.root.state('zoomed')
self.root.resizable(False, False)
self.root.iconbitmap(r"Images\graph_logo.ico")

Page 75 of 87
self.root.title("GRAPH")
title_lbl = Label(self.root, text="GRAPH", font=("Cascadia
Code", 35, "bold"), bg="white", fg="red")
title_lbl.place(x=0, y=
0, width=1366, height=50)
img1 = Image.open(r"Images\bg.jpg")
img1 = img1.resize((1362, 766), Image.ANTIALIAS)
self.photoimg1 = ImageTk.PhotoImage(img1)
f_lbl = Label(self.root, image=self.photoimg1)
f_lbl.place(x=0, y=48)
select_date_label = Label(self.root, text="Select Date:",
font=("Cascadia Code", 12, "bold"), bg="green", fg="white")
select_date_label.place(x=625, y=60)
from_date_label = Label(self.root, text="From:",
font=("Cascadia Code", 12, "bold"))
from_date_label.place(x=440, y=105)
self.var_attendance_date1 = StringVar()
attendance_date1= ttk.Combobox(self.root, font=("Cascadia
Code", 12, "bold"), textvariable=self.var_attendance_date1,
width=15, state="readonly")
if len(os.listdir("Attendance")) > 0:
attendance_date1["values"] = [i.split(".")[0] for i in
os.listdir("Attendance")]
attendance_date1.current(0)
attendance_date1.place(x=510, y=105)
Page 76 of 87
to_date_label = Label(self.root, text="To:", font=("Cascadia
Code", 12, "bold"))
to_date_label.place(x=710, y=105)
self.var_attendance_date2 = StringVar()
attendance_date2 = ttk.Combobox(self.root, font=("Cascadia
Code", 12, "bold"), textvariable=self.var_attendance_date2,
width=15, state="readonly")
if len(os.listdir("Attendance")) > 0:
attendance_date2["values"] = [i.split(".")[0] for i in
os.listdir("Attendance")]
attendance_date2.current(0)
attendance_date2.place(x=760, y=105)
self.btn = Button(self.root, text="PLOT",
command=self.show_graph, cursor="hand2", font=("Cascadia
Code", 12, "bold"), bg="green", fg="white")
self.btn.place(x=600, y=150, width=170)
self.root.bind("<Return>", self.show_graph)
self.f_lbl = Label(self.root, text="THE GRAPH WILL BE
SHOWN HERE AND WILL ALSO BE SAVED IN A FOLDER
NAME 'GRAPHS'", font=("Cascadia Code", 12, "bold"))
self.f_lbl.pack(pady=(200, 0))
def show_graph(self, event=""):
try:
if self.var_attendance_date1.get() != "" and
self.var_attendance_date2.get() != "":
dt1 = self.var_attendance_date1.get().split("-")
Page 77 of 87
dt2 = self.var_attendance_date2.get().split("-")
date1 = datetime(int(dt1[2]), int(dt1[1]), int(dt1[0]))
date2 = datetime(int(dt2[2]), int(dt2[1]), int(dt2[0]))
file = os.listdir("Attendance")
if date2 > date1 or date1 == date2:
df = pd.read_csv(f"Attendance\\
{self.var_attendance_date1.get()}.csv")
rows = len(df.index)
x_vals = []
dt = {}
lt = [i.split(".")[0] for i in os.listdir("Attendance")]
lt2 = [datetime(int(d.split("-")[2]), int(d.split("-")[1]),
int(d.split("-")[0])) for d in lt]
lt2.sort()
start = lt2.index(date1)
stop = lt2.index(date2)
for i in range(start, stop+1):
x_vals.append(lt2[i].strftime("%d-%m-%Y"))
df = pd.read_csv(f'Attendance\\{lt2[i].strftime("%d-
%m-%Y")}.csv')
lt_total = list(df.Attendance)
p_count = lt_total.count("Present")
a_count = lt_total.count("Absent")

Page 78 of 87
dt[lt2[i].strftime("%d-%m-%Y")] = [p_count,
a_count]
n_present = [vals[0] for vals in dt.values()]
n_absent = [vals[1] for vals in dt.values()]
r = np.arange(len(dt.keys()))
plt.bar(r, n_present, width=0.25, color="g")
plt.bar(r+0.25, n_absent, width=0.25, color="r")
plt.xticks(r+0.25/2, x_vals)
plt.yticks([i for i in range(max(max(n_present),
max(n_absent))+1)])
plt.xlabel("Dates")
plt.ylabel("Number of Teachers")
plt.legend(["Present", "Absent"], loc="upper left")
if self.var_attendance_date1.get() !=
self.var_attendance_date2.get():
plt.savefig(f"Graphs\\
{self.var_attendance_date1.get()} to
{self.var_attendance_date2.get()}.jpg")
img2 = Image.open(f"Graphs\\
{self.var_attendance_date1.get()} to
{self.var_attendance_date2.get()}.jpg")
else:
plt.savefig(f"Graphs\\
{self.var_attendance_date1.get()}.jpg")
img2 = Image.open(f"Graphs\\
{self.var_attendance_date1.get()}.jpg")
Page 79 of 87
plt.close()
img2 = img2.resize((800, 500), Image.ANTIALIAS)
self.photoimg2 = ImageTk.PhotoImage(img2)
self.f_lbl.config(image=self.photoimg2)
else:
messagebox.showinfo("ERROR!", "INVALID!",
parent=self.root)
else:
messagebox.showerror("ERROR!", "NO DATA
FOUND!", parent=self.root)
except Exception as e:
messagebox.showerror("ERROR!", f"ERROR: {e}",
parent=self.root)
def mysql_func():
global conn, my_cursor
conn = sql.connect(host="localhost", username=mysql_user,
password=mysql_pass)
my_cursor = conn.cursor()
my_cursor.execute("CREATE DATABASE IF NOT EXISTS
Face;")
my_cursor.execute("USE Face;")
my_cursor.execute("CREATE TABLE IF NOT EXISTS Issues
(S_No INT NOT NULL AUTO_INCREMENT, Name
VARCHAR(45) DEFAULT NULL, Email VARCHAR(45) DEFAULT
NULL, Contact_No BIGINT DEFAULT NULL, Issue
VARCHAR(200) DEFAULT NULL, PRIMARY KEY (S_no));")
Page 80 of 87
my_cursor.execute("CREATE TABLE IF NOT EXISTS Register
(First_Name VARCHAR(45) DEFAULT NULL, Last_Name
VARCHAR(45) DEFAULT NULL, Contact_No BIGINT DEFAULT
NULL, Email VARCHAR(45) NOT NULL, Security_Q
VARCHAR(45) DEFAULT NULL, Security_A VARCHAR(45)
DEFAULT NULL, Password VARCHAR(45) DEFAULT NULL,
PRIMARY KEY (Email));")
my_cursor.execute("CREATE TABLE IF NOT EXISTS Teacher
(Department VARCHAR(45) DEFAULT NULL, Category
VARCHAR(45) DEFAULT NULL, Year VARCHAR(45) DEFAULT
NULL, Semester VARCHAR(45) DEFAULT NULL, Teacher_ID
INT NOT NULL, Teacher_Name VARCHAR(45) DEFAULT NULL,
Class_Teacher VARCHAR(45) DEFAULT NULL, Table_No
VARCHAR(45) DEFAULT NULL, Gender VARCHAR(45)
DEFAULT NULL, DOB VARCHAR(45) DEFAULT NULL, Email
VARCHAR(45) DEFAULT NULL, Phone BIGINT DEFAULT
NULL, Address VARCHAR(100) DEFAULT NULL,
Staff_Room_No INT DEFAULT NULL, Photo_Sample
VARCHAR(45) DEFAULT NULL, PRIMARY KEY (Teacher_ID));")
conn.commit()
def main():
global mysql_user, mysql_pass
def save_func(event=""):
global mysql_user, mysql_pass
try:
if mysql_username.get() == "" or mysql_password.get() ==
"":
messagebox.showerror("ERROR!", "Please Type the
Username and Password")
Page 81 of 87
else:
mysql_user = mysql_username.get()
mysql_pass = mysql_password.get()
mysql_func()
with open("pass.txt", "w") as f:
f.write(f"Username:{mysql_username.get()}\n")
f.write(f"Password:{mysql_password.get()}")
messagebox.showinfo("SUCCESS!", "Access
Granted!", parent=win)
win.destroy()
Login_Window()
except:
messagebox.showinfo("ERROR!", "Wrong Credentials!",
parent=win)
if "pass.txt" not in lt:
win = Tk()
win.geometry("+500+300")
win.resizable(0, 0)
win.iconbitmap(r"Images\db_credentials.ico")
win.title("MYSQL CREDENTIALS")
win.config(bg="cyan")
style = ttk.Style()
style.theme_use("clam")

Page 82 of 87
lbl2 = Label(win, text="Enter your Mysql Server Username:",
font=("Cascadia Code", 15, "bold"), fg="green", bg="black")
lbl2.pack(pady=(10, 0))
mysql_username = StringVar()
user_entry = ttk.Entry(win, textvariable=mysql_username,
width=20, font=("Cascadia Code", 12, "bold"))
user_entry.pack(pady=(10, 0))
user_entry.focus()
lbl2 = Label(win, text="Enter your Mysql Server Password:",
font=("Cascadia Code", 15, "bold"), fg="blue", bg="black")
lbl2.pack(pady=(10, 0))
mysql_password = StringVar()
pass_entry = ttk.Entry(win, textvariable=mysql_password,
width=20, show="*", font=("Cascadia Code", 12, "bold"))
pass_entry.pack(pady=(10, 0))
btn = Button(win, text="SAVE", command=save_func,
width=10, cursor="hand2", font=("Cascadia Code", 12, "bold"),
fg="red", bg="black")
btn.pack(pady=10)
win.bind("<Return>", save_func)
win.mainloop()
else:
try:
with open("pass.txt", "r") as f:
content = f.readlines()
Page 83 of 87
mysql_user = content[0].split(":")[1]
mysql_pass = content[1].split(":")[1]
mysql_func()
Login_Window()
except:
os.remove("pass.txt")
lt = os.listdir()
if "Data" not in lt:
os.mkdir("Data")
if "Attendance" not in lt:
os.mkdir("Attendance")
if "Graphs" not in lt:
os.mkdir("Graphs")
main()

Page 84 of 87
CONCLUSION

There may be various types of lighting conditions, seating


arrangements and environments in various classrooms. Most of
these conditions have been tested on the system and system has
shown 100% accuracy for most of the cases. There may also
exist students portraying various facial expressions, varying hair
styles, beard, spectacles etc. All of these cases are considered
and tested to obtain a high level of accuracy and efficiency.
Thus, it can be concluded from the above discussion that a
reliable, secure, fast and an efficient system has been developed
replacing a manual and unreliable system. This system can be
implemented for better results regarding the management of
attendance and leaves. The system will save time, reduce the
amount of work the administration has to do and will replace the
stationery material with electronic apparatus and reduces the
amount of human resource required for the purpose. Hence a
system with expected results has been developed but there is still
some room for improvement

Page 85 of 87
TEAM MEMBERS

 Manish Kumar Nayak


 Raj
 Keshav Saini

Page 86 of 87
REFERENCES

BOOKS
1. PYTHON: THE COMPLETE REFERENCE BY MARTIN
BROWN
2. TOGETHER WITH INFORMATICS
PRACTICESRACHNA SAGAR
3. TKINTER PROGRAMMING E-BOOK

WEBSITES
1. https://docs.python.org/
2. http://www.stackoverflow.com/
3. http://www.geeksforgeeks.org/

Page 87 of 87

You might also like