Employee Management System (Using Python With Mysql Connectivity)| Python Project with source Code

Published: 03 February 2021
on channel: Minati panda
2,774
like

Donot forget to subscribe the channel if you like the video.
Watch the previous video to design the front end
First we have to create the database and then create the table
Source code:
import everything from tkinter
from tkinter import *
from tkinter import ttk
import tkinter.messagebox as MessageBox
window=Tk()
window.title("Employee Management System")
import mysql.connector as sql1
mycon=sql1.connect(host='localhost',
user='root',
passwd='Mother@75',
database='new_employee')
if mycon.is_connected()== False:
print('Error connecting to MySQL Database')
else:
cursor=mycon.cursor()
#cursor.execute("create table new_employee(emp_no integer primary key,emp_name char(30),emp_Address char(100),phone_no integer)")
#print("Table created successfully")
#Define all functions

def viewall():
cursor.execute("select * from new_employee")
rows=cursor.fetchall()
for row in rows:
insertdata=str(row[1])
list1.insert(list1.size()+1,insertdata)
def addemployee():
e_no=e1.get()
e_name=e2.get()
e_address=e3.get()
e_phoneno=e4.get()
if(e_no=="" or e_name=="" or e_address== "" or e_phoneno==""):
MessageBox.showinfo("Insert status","Fill all the fields")
else:
st="insert into new_employee(emp_no,emp_name,emp_address,phone_no) values({},'{}','{}','{}')".format(e_no,e_name,e_address,e_phoneno)
cursor.execute(st)
mycon.commit()
print("one row inserted")
e1.delete(0,'end')
e2.delete(0,'end')
e3.delete(0,'end')
e4.delete(0,'end')
def updateemployee():
e_no=e1.get()
e_name=e2.get()
e_address=e3.get()
e_phoneno=e4.get()
if(e_no=="" or e_name=="" or e_address== "" or e_phoneno==""):
MessageBox.showinfo("update status","Fill all the fields")
else:
st="update new_employee set emp_name='{}',emp_address='{}',phone_no='{}'".format(e_name,e_address,e_phoneno)
cursor.execute(st)
mycon.commit()
print("one row updated")
e1.delete(0,'end')
e2.delete(0,'end')
e3.delete(0,'end')
e4.delete(0,'end')
def searchemployee():
e_no=e1.get()
if(e_no==""):
MessageBox.showinfo("search status","Employee Number is necessary")
else:
cursor.execute("select * from new_employee where emp_no={}".format(e_no))
rows=cursor.fetchall()
for row in rows:
e2.insert(0,row[1])
e3.insert(0,row[2])
e4.insert(0,row[3])
def deleteemployee():
e_no=e1.get()
if(e_no==""):
MessageBox.showinfo("Delete status","Employee Number is necessary")
else:
st="delete from new_employee where emp_no={}".format(e_no)
cursor.execute(st)
mycon.commit()
print("one row deleted")
def close():
res=MessageBox.askquestion(message="Do you want to exit, press yes or no")
if res== 'yes':
window.destroy()


#define labels
l1=Label(window,text="Employee Number")
l1.grid(row=0,column=0)
l2=Label(window,text="Employee Name")
l2.grid(row=0,column=2)
l3=Label(window,text="Address")
l3.grid(row=1,column=0)
l4=Label(window,text="Phone Number")
l4.grid(row=1,column=2)
#define entries
no_text=StringVar()
e1=Entry(window,textvariable=no_text)
e1.grid(row=0,column=1)
name_text=StringVar()
e2=Entry(window,textvariable=name_text)
e2.grid(row=0,column=3)
address_text=StringVar()
e3=Entry(window,textvariable=address_text)
e3.grid(row=1,column=1)
phoneno_text=StringVar()
e4=Entry(window,textvariable=phoneno_text)
e4.grid(row=1,column=3)
Define listbox
list1=Listbox(window,height=6,width=40)
list1.grid(row=2,column=0,rowspan=6,columnspan=2)
sb1=Scrollbar(window)
sb1.grid(row=2,column=2,rowspan=6)
list1.configure(yscrollcommand=sb1.set)
sb1.configure(command=list1.yview)
#define button
b1=Button(window,text="View All",width=20,command=viewall)
b1.grid(row=2,column=3)
b1=Button(window,text="Search Employee",width=20,command=searchemployee)
b1.grid(row=3,column=3)
b1=Button(window,text="Add Employee",width=20,command=addemployee)
b1.grid(row=4,column=3)
b1=Button(window,text="Update Employee",width=20,command=updateemployee)
b1.grid(row=5,column=3)
b1=Button(window,text="Delete Employee",width=20,command=deleteemployee)
b1.grid(row=6,column=3)
b1=Button(window,text="Close",width=20,command=close)
b1.grid(row=7,column=3)
If you like the video don't forget to subscribe the channel
   / @minatipanda7456  
Link for sql tutorial
   • My SQL Class XII  
Link for tkinter tutorial
   • TKINTER GUIs IN PYTHON | Displaying I...  
Link for class XI videos
   • CLASS XI COMPUTER SCIENCE  
Link for class XII videos
   • Class XII Computer Science