Book Image

Mastering GUI Programming with Python

By : Alan D. Moore
5 (2)
Book Image

Mastering GUI Programming with Python

5 (2)
By: Alan D. Moore

Overview of this book

PyQt5 has long been the most powerful and comprehensive GUI framework available for Python, yet there is a lack of cohesive resources available for Python programmers to learn how to use it. This book will be your comprehensive guide to exploring GUI development with PyQt5. You will get started with an introduction to PyQt5, before going on to develop stunning GUIs with modern features. You will learn how to build forms using QWidgets and delve into important aspects of GUI development such as layouts, size policies, and event-driven programming. Moving ahead, you’ll discover PyQt5’s most powerful features through chapters on audio-visual programming with QtMultimedia, database-driven software with QtSQL, and web browsing with QtWebEngine. Next, in-depth coverage of multithreading and asynchronous programming will help you run tasks asynchronously and build high-concurrency processes with ease. In later chapters, you’ll gain insights into QOpenGLWidget, along with mastering techniques for creating 2D graphics with QPainter. You’ll also explore PyQt on a Raspberry Pi and interface it with remote systems using QtNetwork. Finally, you will learn how to distribute your applications using setuptools and PyInstaller. By the end of this book, you will have the skills you need to develop robust GUI applications using PyQt.
Table of Contents (24 chapters)
Free Chapter
1
Section 1: Deep Dive into PyQt
8
Section 2: Working with External Resources
12
Section 3: Unraveling Advanced Qt Implementations
22
Upgrading Raspbian 9 to Raspbian 10

What this book covers

Chapter 1, Getting Started with PyQt, introduces you to the Qt and PyQt libraries. You will learn how to set up your system for writing PyQt applications and be introduced to Qt Designer. You will also write the traditional Hello World application and develop a basic template for PyQt apps.

Chapter 2, Building Forms with QtWidgets, shows you the basics of making a PyQt GUI. You'll meet the most common input and display widgets, learn to arrange them using layouts, and learn how to validate user input. You'll put these skills into action developing a calendar GUI.

Chapter 3, Handling Events with Signals and Slots, focuses on PyQt's event handling and object communication system. You'll learn how to use this system to make your application respond to user input, and how to create custom signals and slots. You'll put these skills to work by completing your calendar application.

Chapter 4, Building Applications with QMainWindow, introduces you to the QMainWindow class, which forms the basis of our applications throughout the rest of the book. You'll also explore PyQt's standard dialog classes and the QSettings module for saving your app's configuration.

Chapter 5, Creating Data Interfaces with Model-View Classes, focuses on Qt's Model-View classes. You'll learn the principles of model-view design, explore the model-view classes in QtWidgets, and exercise your knowledge as we develop a CSV editor.

Chapter 6, Styling Qt Applications, explores the styling capabilities of PyQt widgets. You will spice up your GUI applications with custom fonts, images, and icons. You'll learn to customize colors using style objects and Qt style sheets. Finally, we'll learn how to do basic animations of style properties.

Chapter 7, Working with Audio-Visual Using QtMultimedia, explores the multimedia features of Qt. You will learn how to playback and record audio and video in a way that works seamlessly across platforms.

Chapter 8, Networking with QtNetwork, is focused on simple network communications using the QtNetwork library. You will learn to communicate over raw sockets, both Transmission Control Protocol (TCP) and User Datagram Protocol (UDP), as well as learning to transmit and receive files and data using HTTP.

Chapter 9, Exploring SQL with QtSQL, introduces you to the world of SQL database programming. You will learn the basics of SQL and the SQLite database. You will then learn how your PyQt applications can use the QtSQL library to access data using raw SQL commands or Qt's SQL model-view classes.

Chapter 10, Multithreading with QTimer and QThread, addresses the world of multithreaded and asynchronous programming. You will learn to use timers to delay tasks on the event loop and learn how to push processes into a separate execution thread using QThread. You'll also learn how to do high-concurrency programming using QThreadPool.

Chapter 11, Creating Rich Text with QTextDocument, explores rich text and document preparation in Qt. You'll be introduced to Qt's rich text markup language, and learn how to build documents programmatically using QTextDocument. You'll also learn how to use Qt's printing libraries to enable document printing easily across platforms.

Chapter 12, Creating 2D Graphics with Qpainter, digs deep into two-dimensional graphics in Qt. You'll learn how to load and edit images and to create custom widgets. You'll also learn about drawing and animating with the Qt Graphics system, and create an arcade-style game.

Chapter 13, Creating 3D Graphics with QtOpenGL, introduces you to 3D graphics with OpenGL. You will learn the basics of modern OpenGL programming, and how to use PyQt widgets to display and interact with OpenGL drawings.

Chapter 14, Embedding Data Plots with QtCharts, explores Qt's built-in charting capabilities. You'll learn how to create both static and animated charts, and how to customize the colors, fonts, and styles of your charts.

Chapter 15, PyQt Raspberry Pi, focuses on the use of PyQt on the Raspberry Pi computer. You'll learn how to set up PyQt on Raspbian Linux, and how to combine the power of PyQt with the Raspberry Pi's GPIO pins to create GUI applications that interact with real-world circuitry.

Chapter 16, Web Browsing with QtWebEngine, looks at PyQt's Chromium-based web browser module. You'll explore the capabilities of this module as you build your own multi-tabbed web browser.

Chapter 17, Preparing your Software for Distribution, discusses various ways to prepare your code for sharing and distribution. We'll look at optimal project layout, packaging your source code for other Python users using setuptools, and building standalone executables using PyInstaller.

Appendix A, Answers to Questions, contains answers or suggestions for the questions at the end of each chapter.

Appendix B, Upgrading Raspbian 9 to Raspbian 10, explains how to upgrade a Raspberry Pi device from Raspbian 9 to Raspbian 10, for readers who are trying to follow the book before the official release of Raspbian 10.