DEV Community

Cover image for Employee Management System using Python.
Ebikara Spiff
Ebikara Spiff

Posted on • Updated on

Employee Management System using Python.

Introduction

Dealing with piles of papers or scattered Excel sheets for employee information can be a real headache, right? Well, what if I told you there's a smoother way to handle all that? A system that lets you easily store, update, and find details about your employees in just a few clicks. Sounds neat, doesn't it? In this article, you're going to explore creating an employee management system using Python, Tkinter, and SQLite3.

Now, employee management systems have evolved into must-haves for businesses to keep their workforce in check. You can start from the basics, like employee names and contacts, all the way to tracking their attendance and performance evaluations. By automating these tasks, you not only save time but also minimize errors, making it a win-win situation for everyone involved.

So, what's the goal here? Well, building a personalised employee management system using Python's Tkinter for crafting the interface and SQLite3 for managing the database. You'll cover creating an easy-to-use data entry screen, handling data storage and retrieval smoothly, and even giving hints on how to level up the system according to your company's needs. By the time you finish reading, you'll be all set to craft your employee management system that fits your business like a glove.

Project Setup

When working in Visual Studio Code (VS Code), always create a new Python file for your project.

It's helpful to have separate files for different parts of your project.

To do this, you can start by opening your VS Code and creating a new folder:

Step 1

Open VS Code

Vs Code Home page

Step 2

Create new folder

New Folder on Vs Code

Step 3

Head over to the newly created folder and create a new file app.py.

new file on vs code

Before you dive in, you will start by installing and importing the necessary libraries.

Step 4

Install the necessary library:



pip install customtkinter
pip install sqlite3


Enter fullscreen mode Exit fullscreen mode

Step 5

Next, Import the necessary libraries:



import sqlite3
import customtkinter
from tkinter import messagebox
from tkinter import *
from tkinter import ttk


Enter fullscreen mode Exit fullscreen mode

sqlite3 - This helps store and handle employee data in a database.

customtkinter - This is a special toolkit for making the system look and work a certain way.

messagebox (from tkinter): This shows messages or notifications to the user.

tkinter - This is the main tool for creating the system's visual interface.

ttk (from tkinter) -This helps make the system's design look more modern and consistent across different computers.

When you use the asterisk (*) symbol in the import statement in Python, such as from tkinter import * it brings all the names from the module directly into your code. This can make it easier to access things.

Database Connection & Function

When you're creating an employee management system with Python, Database Connection & Functions basically means hooking up a database to your system and making sure it can do everything you need it to do with the employee information. So, it's like setting up a connection between your Python code and the database and then adding in functions to add, update, and delete employee records. It's all about making sure your system can handle employee data smoothly and efficiently.

Step 1

Start by creating a simple window. You'll begin by setting up a variable app:



app = customtkinter.CTK()
app.title("Employee System")
app.geometry("800x500")
app.config(bg="#17043d")


Enter fullscreen mode Exit fullscreen mode

Step 2

Define different fonts that you will use for your buttons and entry boxes. These fonts will help you maintain consistency in the appearance of text displayed on buttons and entry boxes within your application. By setting these fonts, you can easily apply them to different widgets throughout your Employee System interface:



font1 = (Arial, 20, bold)
font2= (Arial, 15, bold)
font3 = (Arial,12, bold)


Enter fullscreen mode Exit fullscreen mode

Step 3

Add a frame inside the window next:



frame1 = customtkinter.CTkFrame(app, fg_color="#FFFFFF")
frame1.place(x=350, y=0, width=450, height=500)


Enter fullscreen mode Exit fullscreen mode

Step 4

See how your main window looks:



app.mainloop()


Enter fullscreen mode Exit fullscreen mode

Step 5

Save and run the code written so far.

Main Window of Employee Management System

Setting up an Employee Database in SQLite

When setting up an employee database, you're essentially creating a well-organized system where you can easily access and manage information about your employees. Think of it as having everything neatly arranged on digital shelves. Each employee gets their spot in the database with all the key details, like their name, job role, department, and contact information, laid out in a structured way. This makes it super convenient to search for particular details when you need them.

Step 1

Establish a connection to SQLite database with name: Employee.db using thesqlite3.connect() method. By creating this table in the database, you'll be able to conveniently store and retrieve employee data for different tasks and operations in your application. This will help you efficiently manage and work with employee information as needed:



db = sqlite3.connect("Employee.db")
db.execute("CREATE TABLE IF NOT EXISTS EMPLOYEES (Employee_ID INTEGER, Name TEXT, Age TEXT, Role TEXT)")


Enter fullscreen mode Exit fullscreen mode

Labels & Entry Boxes & Combo Box

When creating an employee management system with Python, labels, entry boxes, and combo boxes are essential for building a user-friendly interface that guides users through the process. Labels help by showing text or instructions; entry boxes allow users to input data such as employee details; and combo boxes simplify the selection of options from a list. By combining these elements, the system becomes more intuitive and enhances the overall user experience. So, including these GUI components is crucial for effectively managing employee data and ensuring smooth user interaction.

Here, Create and define your labels ID,Name,Age,Role.

Step 1

Create a user input form with a label ID: and an entry field:



id_label = customtkinter.CTkLabel(app, text="ID:", text_font=font1)
id_label.place(x=20, y=20)
id_entry = customtkinter.CTkEntry(app, text_font=font2, text_color="#000000", fg_color="#FFFFFF", border_color="#FFFFFF", width=200)
id_entry.place(x=140, y=20)


Enter fullscreen mode Exit fullscreen mode

Step 2

Next, Create a user input form with a label Name: and an entry field:



name_label = customtkinter.CTkLabel(app, text="Name:", text_font=font1)
name_label.place(x=20, y=80)
name_entry = customtkinter.CTkEntry(app, text_font=font2, text_color="#000000", fg_color="#FFFFFF", border_color="#FFFFFF", width=200)
name_entry.place(x=140, y=80)


Enter fullscreen mode Exit fullscreen mode

Step 3

Create a user input form with the label Age: and an entry field:



age_label = customtkinter.CTkLabel(app, text="Age:", text_font=font1)
age_label.place(x=20, y=140)
age_entry = customtkinter.CTkEntry(app, text_font=font2, text_color="#000000", fg_color="#FFFFFF", border_color="#FFFFFF", width=200)
age_entry.place(x=140, y=140)


Enter fullscreen mode Exit fullscreen mode

Step 4

Finally, create a user input form with the label Role: and an entry field:



role_label = customtkinter.CTkLabel(app, text="Role:", text_font=font1)
role_label.place(x=20, y=200)
role_entry = customtkinter.CTkEntry(app, text_font=font2, text_color="#000000", fg_color="#FFFFFF", border_color="#FFFFFF", width=200)
role_entry.place(x=140, y=200)


Enter fullscreen mode Exit fullscreen mode

Step 5

Save and run the code written so far.

Image of our main window with labels,entry boxes and combo box

Buttons

In an employee management system, buttons are like tools that help users do things like add, change, or remove employee information. Well-designed buttons make it simple for users to navigate and control tasks smoothly.
To create the buttons for our windows, you will create and define new variables.

Step 1

In this step, you will define and create a Save button for the Employee Management System window. The Save button is crucial for adding new employee information to the system. It allows users to save the data entered in the input fields:



save_button = customtkinter.CTkButton(app, command=insert, text="Save", text_font=font1, fg_color="#03a819", hover_color="#03a819", corner_radius=20, width=120, cursor="hand2")
save_button.place(x=70, y=250)


Enter fullscreen mode Exit fullscreen mode

Step 2

Next, Define and create an Update button for the window. The Update button facilitates the modification of existing employee records within the system:



update_button = customtkinter.CTkButton(app, command=update, text="Update", text_font=font1, fg_color="#b86512", hover_color="#b86512", corner_radius=20, width=127, cursor="hand2")
update_button.place(x=200, y=250)


Enter fullscreen mode Exit fullscreen mode

Step 3

Here, create a Clear button for the window. The Clear button offers users a way to remove input data or reset the form fields:



clear_button = customtkinter.CTkButton(app, command=clear, text="Clear", text_font=font1, fg_color="#6e0e53", hover_color="#6e0e53", corner_radius=20, width=120, cursor="hand2")
clear_button.place(x=70, y=300)


Enter fullscreen mode Exit fullscreen mode

Step 4

In the final step, Define a Delete button for the window. The Deletebutton enables the removal of selected employee records from the system:



delete_button = customtkinter.CTkButton(app, command=delete, text="Delete", text_font=font1, fg_color="#cf061a", hover_color="#cf061a", corner_radius=20, width=140, cursor="hand2")
delete_button.place(x=200, y=300)


Enter fullscreen mode Exit fullscreen mode

Step 5

Save and run the code written so far.

Image of our Buttons

Treeview

When you're making an employee management system with Python, treeviewis like a digital tree that helps organise your employee information. It sorts them into groups by things like departments and shows them in a neat list. It's a helpful way to keep track of who's on your team.

Step 1

First, Use the tree view to insert the employee details:



style = ttk.Style()


Enter fullscreen mode Exit fullscreen mode

Step 2

Next, modify the body font:



style.configure("mystyle.Treeview", font=font3, rowheight=50)


Enter fullscreen mode Exit fullscreen mode

Step 3

Modify the heading font:



style.configure("mystyle.Treeview.Heading", font=font2)


Enter fullscreen mode Exit fullscreen mode

Step 4

Here, remove the treeview border:



style.layout("mystyle.Treeview", [("mystyle.Treeview.treearea", {"sticky": "nswe"})])


Enter fullscreen mode Exit fullscreen mode

Step 5

Save and run the code written so far.

Image of our Employee Management System treeview

Insert Data to Tree View

When you're building an employee management system with Python, Insert Data to TreeView simply means adding new employee information to the organised list displayed in the tree view.

Step 1

Create your treeview columns and headings:



tv.heading("1", text="ID")
tv.column("1", width=105)

tv.heading("2", text="Name")
tv.column("2", width=105)

tv.heading("3", text="Age")
tv.column("3", width=105)

tv.heading("4", text="Role")
tv.column("4", width=105)


Enter fullscreen mode Exit fullscreen mode

Step 2

Display the heading of our tree view :



tv.pack()


Enter fullscreen mode Exit fullscreen mode

Step 3

Create your functions to insert your data into the Treeview:



def insert():
    if id_entry.get() == "" or name_entry.get() == "" or age_entry.get() == "" or role_entry.get() == "":
        messagebox.showerror(title="Error", message="Please Enter All The Data.")
    else:
        details = [int(id_entry.get()), name_entry.get(), age_entry.get(), role_entry.get()]
        cursor.execute("INSERT INTO Employee VALUES (?,?,?,?)", details)
        db.commit()
        messagebox.showinfo(title="Inserted", message="Employee Has Been Inserted.")


Enter fullscreen mode Exit fullscreen mode

Step 4

Create another function to clear all entry boxes:



def clear():
    id_entry.delete(0, END)
    name_entry.delete(0, END)
    age_entry.delete(0, END)
    role_entry.delete(0, END)


Enter fullscreen mode Exit fullscreen mode

Step 5

Add the insert function and clear function in save_button and clear_button

save_button.config(command=insert)
clear_button.config(command=clear)

Step 6

Finally, to view every employee's details in the database on your treeview, create new functions fetch and display_data:



def fetch():
    cursor.execute("SELECT * FROM EMPLOYEE")
    rows = cursor.fetchall()
    return rows


Enter fullscreen mode Exit fullscreen mode


def display_data():
    tv.delete(*tv.get_children())
    for row in fetch():
        tv.insert("", END, values=row)


Enter fullscreen mode Exit fullscreen mode

fetch: is responsible for getting every employee from your database.

display_data: is responsible for inserting your data in our tv.

Step 7

Finally, view your display_data in our tv:



display_data()


Enter fullscreen mode Exit fullscreen mode

Step 8

Save the code written.

New Employee Function

Think of the New Employee function as a tool for adding a new employee to your team when you're making an employee management system with Python. It's a way to create a profile for the new team member, where you can put in their name, job title, and other important information. It's like filling out a form to officially bring someone on board. So, it's just a simple way to keep track of who's on your team.

Step 1

Add the display_data function to your insert function:



def insert():
    if id_entry.get() == "" or name_entry.get() == "" or age_entry.get() == "" or role_entry.get() == "":
        messagebox.showerror(title="Error", message="Please Enter All The Data.")
    else:
        details=[int(id_entry.get()), name_entry.get(), age_entry.get(), role_entry.get()]
        cursor.execute("INSERT INTO Employee VALUES (?,?,?,?)", details)
        db.commit()
        messagebox.showinfo(title="Inserted", message="Employee Has Been Inserted.")
        display_data()


Enter fullscreen mode Exit fullscreen mode

Step 2

Save and run the code.

Image of our employee management system with new employee data

Delete function

Okay, so imagine you have your employee list all set up in your system, right? But then, someone leaves the company. You don't want their information hanging around anymore. That's where the delete function comes in handy.
It allows you to remove a specific employee's profile from your system entirely and keeps your employee list accurate and up-to-date.

Step 1

Delete an entry from your database, and to do this, create a new function delete:



def delete():
    cursor.execute("DELETE FROM Employee WHERE Employee_ID=?", [id_entry.get()])
    db.commit()
    messagebox.showinfo(title="Delete", message="Employee Has Been Deleted.")
    display_data()
    clear()


Enter fullscreen mode Exit fullscreen mode

Step 2

Give the delete_button a delete command.

delete_button.config(command=delete)

Step 3

Save the code written so far. Once it's saved, delete employee ID: 150 to see if it works as expected.

Image of our employee management system with employee ID :150

Image of our employee management system without employee ID :150

Update functions

So, say someone on your team gets a promotion, or maybe they move to a different department, or their contact information changes. You don't want to delete their whole profile and start over, right? That's where the update function comes in.

It's like having a little edit button for each employee's profile. You can use it to change any outdated information and make sure everything is current.

Step 1

Create a new function called get_data :



def get_data(event):
   clear()
   selected_row = tv.focus()
   data = tv.item(selected_row)
   row = data["values"]
   id_entry.insert(0, row[0])
   name_entry.insert(0, row[1])
   age_entry.insert(0, row[2])
   role_entry.insert(0, row[3])


Enter fullscreen mode Exit fullscreen mode

Step 2

Call the function get_data:



tv.bind("<ButtonRelease-1>", get_data)


Enter fullscreen mode Exit fullscreen mode

Step 3

Create a new function update and create a new variable inside it :



def update():
    new_details = [name_entry.get(), age_entry.get(), role_entry.get(), int(id_entry.get())]
    cursor.execute("UPDATE Employee SET Name=?, Age=?, Role=? WHERE Employee_ID=?", new_details)
    db.commit()
    messagebox.showinfo(title="UPDATED", message="Employee's details have been updated.")
    display_data()


Enter fullscreen mode Exit fullscreen mode

Step 4

Parse the update_button using the update function with the command set as update.

update_button.config(command=update)

Step 5

Save and run code.

final Image of employee management system

Conclusion

In this article, you learned about making an employee management system using Python. This system helps companies organize employee information easily and accurately. You started by getting everything set up for the project, connecting to a database, and creating functions to add, read, update, and delete employee data. You used Tkinter to create a simple interface with fields for entering data and buttons for performing actions.

You added a feature to display employee details in a structured way using the tree view. This enables you to see all the employee information at a glance. You could also add new employees, delete existing ones, and update their details as needed. Using Python's flexibility and ease of use, you built a practical employee management system that can be customized for different company requirements.

Python's simplicity makes it a good choice for developing efficient and user-friendly management systems. By using Python for such systems, companies can improve efficiency, simplify operations, and make sure employee data is managed effectively.

Top comments (5)

Collapse
 
msaligs profile image
msaligs

Its intresting and good way to learn tinker.

One request i have is to show how to package this so as to install this application on windows or linux.

Collapse
 
spiff profile image
Ebikara Spiff

Thank you for your comment .
When I am a little less busy with work, I will try to grant your request and write how to install this application on windows or linux.

Collapse
 
sreno77 profile image
Scott Reno

Very cool project

Collapse
 
spiff profile image
Ebikara Spiff

Thank you.

Collapse
 
kalyango_elvis profile image
Kalyango Elvis

Great work, how about if you also add tab where you are able to add their salaries.
Can it be able to encompass the oop concepts including encapsulation, inheritance and polymorphism?