0% found this document useful (0 votes)
18 views19 pages

Document 16 1

This document outlines the setup and functionality of a simple Contact Management System using MySQL and Python. It includes SQL code for creating a database and a contacts table, as well as Python code utilizing Tkinter for the GUI to add and display contacts. The system ensures that each contact has a unique identifier and provides a user-friendly interface for managing contact information.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
18 views19 pages

Document 16 1

This document outlines the setup and functionality of a simple Contact Management System using MySQL and Python. It includes SQL code for creating a database and a contacts table, as well as Python code utilizing Tkinter for the GUI to add and display contacts. The system ensures that each contact has a unique identifier and provides a user-friendly interface for managing contact information.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 19

HOW TO

USE?
1.USE MYSQL TO USE THE MYSQL
CODE.
2.USE THE PYTHON CODE WITH THE
MYSQL CODE TO FIND THE OUTPUT.
MySQL
Code
CREATE DATABASE contact_manager;
USE contact_manager;

CREATE TABLE Contacts (


contact_id INT AUTO_INCREMENT
PRIMARY KEY,
name VARCHAR(100) NOT NULL,
phone VARCHAR(15) NOT NULL,
email VARCHAR(100),
created_at TIMESTAMP DEFAULT
CURRENT_TIMESTAMP
);

Overview of the Contact Manager


Database
 Purpose:
o To create a simple database for
managing contact information.
 Key Components:
o Database Creation:
 CREATE DATABASE
contact_manager;
 Establishes a dedicated space for
storing contact data.
o Database Selection:
 USE contact_manager;
 Sets the context for subsequent
operations within the
contact_manager database.
Structure of the Contacts Table
 Table Creation:
o CREATE TABLE Contacts (...)
 Columns:
o contact_id:
 INT AUTO_INCREMENT PRIMARY
KEY
 Unique identifier for each contact.
o name:
 VARCHAR(100) NOT NULL
 Contact's name (mandatory).
o phone:
 VARCHAR(15) NOT NULL
 Contact's phone number
(mandatory).
o email:
 VARCHAR(100)
 Contact's email address (optional).
o created_at:
 TIMESTAMP DEFAULT
CURRENT_TIMESTAMP
 Records the timestamp when the
contact is added.
Note on MySQL Code for Contact
Manager Database

Summary
This code sets up a basic structure for
a contact management system,
allowing users to store and manage
contact information efficiently. The
use of AUTO_INCREMENT for
contact_id ensures that each contact
has a unique identifier, while the
created_at timestamp provides a
record of when each contact was
added.
Python
Code
import tkinter as tk
from tkinter import messagebox
import pymysql

conn = pymysql.connect(
host="localhost",
user="root",
password="root",
database="contact_manager"
)
cursor = conn.cursor()

def add_contact():
name = entry_name.get()
phone = entry_phone.get()
email = entry_email.get()
if name and phone:
cursor.execute("INSERT INTO
Contacts (name, phone, email) VALUES
(%s, %s, %s)", (name, phone, email))
conn.commit()
load_contacts()
entry_name.delete(0, tk.END)
entry_phone.delete(0, tk.END)
entry_email.delete(0, tk.END)
else:
messagebox.showwarning("Input
Error", "Name and Phone are required.")

def load_contacts():
listbox_contacts.delete(0, tk.END)
cursor.execute("SELECT * FROM
Contacts")
for contact in cursor.fetchall():
listbox_contacts.insert(tk.END,
f"{contact[0]} - {contact[1]} |
{contact[2]} | {contact[3]}")

root = tk.Tk()
root.title("Contact Management System")
tk.Label(root, text="Name").pack()
entry_name = tk.Entry(root)
entry_name.pack()

tk.Label(root, text="Phone").pack()
entry_phone = tk.Entry(root)
entry_phone.pack()

tk.Label(root, text="Email").pack()
entry_email = tk.Entry(root)
entry_email.pack()
tk.Button(root, text="Add Contact",
command=add_contact).pack(pady=5)
listbox_contacts = tk.Listbox(root,
width=50, height=10)
listbox_contacts.pack(pady=10)
load_contacts()
root.mainloop()
Slide 1: Overview
 Purpose: A simple Contact Management
System that allows users to add and view
contacts.
 Technologies Used:
o Tkinter: For the graphical user
interface (GUI).
o pymysql: For connecting to a MySQL
database.
Slide 2: Database Connection
 Connection Setup:
o Connects to a MySQL database named
contact_manager.
o Uses credentials:
 Host: localhost
 User: root
 Password: root
 Cursor Creation: A cursor is created to
execute SQL commands.
Slide 3: Adding Contacts
 Function: add_contact()
o Retrieves user input for name, phone,
and email.
o Validates that name and phone are
provided.
o Executes an SQL INSERT command to
add the contact to the Contacts table.
o Clears input fields after successful
addition.
o Displays a warning if required fields
are missing.
Slide 4: Loading Contacts
 Function: load_contacts()
o Clears the current list of contacts in
the GUI.
o Executes an SQL SELECT command to
fetch all contacts from the Contacts
table.
o Displays each contact in a listbox in
the format: ID - Name | Phone |
Email.
Slide 5: User Interface
 Components:
o Labels and Entry fields for Name,
Phone, and Email.
o A button to trigger the addition of a
new contact.
o A Listbox to display the list of contacts.
 Main Loop: The application runs in a loop,
waiting for user interactions.
Output
OTHER CONTACT
MANAGEMENT APPS

You might also like