Contact book with SQLite
A desktop address book to add, search, edit and delete contacts, stored in a real database.
Beginnerâą 5â8 hoursđĒ 7 stepsPythonTkinterSQLite
What you'll learn
- âSQL with Python's sqlite3
- âCRUD operations and parameterised queries
- âShowing tables with ttk.Treeview
What you'll build
- âAdd, edit, delete contacts
- âLive search by name or phone
- âValidation for phone and email
- âExport to CSV
Step-by-step guide
- 1
Create the table
sqlite3.connect("contacts.db") and CREATE TABLE IF NOT EXISTS contacts(id INTEGER PRIMARY KEY, name TEXT NOT NULL, phone TEXT, email TEXT).
- 2
Write data functions
add_contact, update_contact, delete_contact and search_contacts, always using ? placeholders (never string formatting) to avoid SQL injection.
- 3
Build the form
Entry fields for name, phone, email and buttons Add, Update, Delete, Clear.
- 4
Show the list
A ttk.Treeview with columns; reload it after every change.
- 5
Select to edit
Bind <<TreeviewSelect>> to load the selected contact into the form.
- 6
Search
Bind the search Entry's key release to run SELECT ... WHERE name LIKE ? OR phone LIKE ? with f"%{q}%".
- 7
Validate and export
Check a 10-digit phone with a regex; export all rows with csv.writer.
đ Make it stand out
- +Add groups (Family, College, Work)
- +Birthday reminders
- +Import contacts from a CSV