Wednesday, March 10, 2021

Real Python: Build a Contact Book With Python, PyQt, and SQLite

Building projects is arguably one of the more approachable and effective ways of learning to program. Real projects require you to apply different and varied coding skills. They also encourage you to research topics that pop up as you’re solving problems in the development process. In this tutorial, you’ll create a contact book application with Python, PyQt, and SQLite.

In this tutorial, you’ll learn how to:

  • Create a graphical user interface (GUI) for your contact book application using Python and PyQt
  • Connect the application to an SQLite database using PyQt’s SQL support
  • Manage contact data using PyQt’s Model-View architecture

At the end of this project, you’ll have a functional contact book application that will allow you to store and manage your contact information.

To get the complete source code for the application as well as the code for every step you’ll go through in this tutorial, click the link below:

Get the Source Code: Click here to get the source code you’ll use to build a contact book with Python, PyQt, and SQLite in this tutorial.

Demo: A Contact Book With Python

Contact books are a useful and widely used kind of application. They’re everywhere. You probably have a contact book on your phone and on your computer. With a contact book, you can store and manage contact information for your family members, friends, coworkers, and so on.

In this tutorial, you’ll code a contact book GUI application with Python, SQLite, and PyQt. Here’s a demo of how your contact book will look and work after you follow the steps in this tutorial:

Your contact book will provide the minimal required set of features for this kind of application. You’ll be able to display, create, update, and remove the information in your contacts list.

Project Overview

To build your contact book application, you need to organize the code into modules and packages and give your project a coherent structure. In this tutorial, you’ll use the following directories and files structure:

rpcontacts_project/
│
├── rpcontacts/
│   ├── __init__.py
│   ├── views.py
│   ├── database.py
│   ├── main.py
│   └── model.py
│
├── requirements.txt
├── README.md
└── rpcontacts.py

Here’s a brief summary of the contents of your project directory:

  • rpcontacts_project/ is the project’s root directory. It’ll contain the following files:
    • requirements.txt provides the project’s requirements list.
    • README.md provides general information about the project.
    • rpcontacts.py provides the entry-point script to run the application.
  • rpcontacts/ is a subdirectory that provides the application’s main package. It provides the following modules:
    • __init__.py
    • views.py
    • database.py
    • main.py
    • model.py

You’ll cover each of these files step by step in this tutorial. The name of each file gives an idea of its role in the application. For example, views.py will contain the code to generate the GUI of windows and dialogs, database.py will contain code to work with the database, and main.py will host the application itself. Finally, model.py will implement the model to manage the data in the application’s database.

In general, the application will have a main window to display, add, remove, and update contacts. It’ll also have a dialog to add new contacts to the database.

Prerequisites

To get the most out of this project, some previous knowledge of GUI programming with Python and PyQt would help. In this regard, you’ll need to know the basics of how to:

  • Create GUI applications with PyQt and Python
  • Build and lay out GUIs with PyQt
  • Manage SQL databases with Python and PyQt
  • Work with SQLite databases

To brush up on these topics, you can check out the following resources:

Don’t worry if you’re not an expert in these areas before starting this tutorial. You’ll learn through the process of getting your hands dirty on a real project. If you get stuck, then take your time and review the resources linked above. Then get back to the code.

The contact book application you’re going to build in this tutorial has a single external dependency: PyQt.

Read the full article at https://realpython.com/python-contact-book/ »


[ Improve Your Python With 🐍 Python Tricks 💌 – Get a short & sweet Python Trick delivered to your inbox every couple of days. >> Click here to learn more and see examples ]



from Planet Python
via read more

No comments:

Post a Comment

TestDriven.io: Working with Static and Media Files in Django

This article looks at how to work with static and media files in a Django project, locally and in production. from Planet Python via read...