Create a Contact Management System Project in Python

A contact management system application, showing multiple buttons on the right side and several contact entities on the left side.

Introduction

In today’s fast-paced world, contact management systems have become an essential tool for businesses, organisations, and individuals alike. Contact management systems are designed to help you keep track of your contacts, manage your relationships with them, and improve communication. They are powerful tools that can help you streamline your business processes and boost productivity.

A contact management system is a software application that is designed to organize and manage your contact information. This information can include names, phone numbers, email addresses, physical addresses, job titles, and other relevant details. The system allows you to store and retrieve contact information quickly and easily. In this tutorial, we will develop such a Contact Management System Project in Python with MySQL.

Our Contact Management System will manage the following tasks:

  1. Add a new record: Name, Surname, Address, Contact, and Email (a valid email: the program will check an email address valid or not using regular expressions).
  2. Display contact information: It shows all the records in a table view format.
  3. Search a record by the Name or Surname of a person.
  4. Update a record: Users need to double-click on a record to perform this operation.
  5. Delete a record.

The Project Details

The graphical interface of this contact manager program is managed by the Tkinter library. The PyMySQL package is used here to manage database operations using python. The project folder contains four python files, ‘main.py’, ‘custom.py’, ‘credentials.py’, and ‘validemail.py’. 

  • main.py‘ – This handles all the Contact Management tasks.
  • custom.py‘ – It has several information about the color and font used by the main program. 
  • credentials.py‘ – It contains credentials to log in to the MySQL server. 
  • validemail.py‘ – Checks whether an email ID is valid or not using the regular expressions and returns a bool value.

As we’ll be interacting with the database, it’s essential to have MySQL Server installed on your system (You can find instructions on how to install MySQL on WindowsLinux, and Mac). If you’ve already completed this step, there’s no need to do it again.

Create a Database and a Table

Create a database with this name: “contact_management“.

create database contact_management;

Create a table “contact_register” under the “contact_management” database.

create table contact_register(
	f_name VARCHAR(50) NOT NULL,
	l_name VARCHAR(50) NOT NULL,
	address VARCHAR(200) NOT NULL,
	contact VARCHAR(15) NOT NULL,
	email VARCHAR(100) NOT NULL,
	PRIMARY KEY ( contact )
);

Create a Dedicated MySQL User and Grant Privileges

I suggest to create a specific MySQL user exclusively for this project and grant the necessary privileges. Please perform the following steps:

1. Log in to MySQL:

You’ll need to have administrative access to your MySQL server. You can log in using the MySQL command-line client:

mysql -u root -p

Replace root with your MySQL username if it’s different, and you’ll be prompted for the MySQL root password.

2. Create a New User:

To create a new MySQL user, you can use the `CREATE USER` command. Replace `username` and `password` with your desired username and password:

CREATE USER 'username'@'localhost' IDENTIFIED BY 'password';

This creates a user called `username` that can only connect from the local machine. If you want to allow connections from any host, replace `localhost` with `%`.

3. Grant Privileges:

You can use the `GRANT` statement to assign privileges to the user. Here’s how to grant various privileges:

Grant all privileges on a specific database:

GRANT ALL PRIVILEGES ON database_name.* TO 'username'@'localhost';

Grant specific privileges (e.g., GRANT CREATE, ALTER, DROP, INSERT, UPDATE, INDEX, DELETE, SELECT, REFERENCES, RELOAD) on a specific database:

GRANT SELECT, INSERT, UPDATE, DELETE ON database_name.* TO 'username'@'localhost';

Replace `database_name` with the name of the database you want to grant access to.

Grant all privileges on all databases (not recommended for security reasons):

GRANT ALL PRIVILEGES ON *.* TO 'username'@'localhost';

4. Apply Privileges:

After granting privileges, you need to apply the changes using the FLUSH PRIVILEGES command:

FLUSH PRIVILEGES;

5. Exit MySQL:

Now you can exit the MySQL Client:

exit;

Requirements and Installation

Make sure that you have Python installed on your system. You will also need to install PyMySQL library for connecting to and interacting with MySQL databases.

pip install PyMySQL

Note that, by default Tkinter comes with most Python installations, so you likely won’t need to install it separately. However, if you don’t have it, you can install it using pip:

pip install tk

What can you learn from this project?

Output

Be sure to watch the complete video to understand how this Contact Management System operates.

Download the Source Code

Download the project files through the Download button below. The files will be in a zip format, and you’ll need to extract them to access the primary program files.

Summary

In this tutorial, we discussed how to create a Contact Management System Project in Python. Here we have handled graphical interface and database-related tasks using Tkinter and MySQL respectively.

You need to follow some basic things before using this python-based contact management system. For example, Installing MySQL server and all required modules or packages, creating a database and a table, etc.

The code is not suitable for copying and pasting because of its length. Therefore, I’ve provided the Project files in a zip format above, which you can download using the ‘Download’ button. In conclusion, Contact Management Systems are powerful tools that can help you to be more organized, improve your communication, and boost your productivity.

Find more Python Projects related to Python and MySQL here:

👉Student Management System Project in Python with MySQL

👉Create a Login and Registration form using Python and MySQL

👉Library Management System Project in Python with MySQL

If you have any queries or feedback, leave in the comments below. You’ll get a reply soon.

Happy Coding!

Share your love
Subhankar Rakshit
Subhankar Rakshit

Hey there! I’m Subhankar Rakshit, the brains behind PySeek. I’m a Post Graduate in Computer Science. PySeek is where I channel my love for Python programming and share it with the world through engaging and informative blogs.

Articles: 147