🎙 Free live masterclass · Sun, 29 Nov, 7:00 pm IST · Java Full Stack roadmap Register free →
Skills101

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. 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. 2

    Write data functions

    add_contact, update_contact, delete_contact and search_contacts, always using ? placeholders (never string formatting) to avoid SQL injection.

  3. 3

    Build the form

    Entry fields for name, phone, email and buttons Add, Update, Delete, Clear.

  4. 4

    Show the list

    A ttk.Treeview with columns; reload it after every change.

  5. 5

    Select to edit

    Bind <<TreeviewSelect>> to load the selected contact into the form.

  6. 6

    Search

    Bind the search Entry's key release to run SELECT ... WHERE name LIKE ? OR phone LIKE ? with f"%{q}%".

  7. 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