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

Preface

In an age when the term application developer nearly always implies web application developer, the building of desktop GUI applications may seem in danger of becoming a quaint and obscure art. Yet on every forum, mailing list, and chat service where programming is discussed, I find young Python coders eager to dive into GUI toolkits so that they can start building the kind of software that any average person can readily identify as an application. The one GUI library consistently recommended to these learners, the one that is arguably Python's most exciting and most complete toolkit, is PyQt.

Despite this popularity, there have been relatively few resources available for learning PyQt. Those who wish to learn it must rely heavily on outdated books, C++ documentation, scattered blogs, or snippets of code found in mailing lists or Stack Overflow posts. There is an apparent need for a modern tutorial and reference on PyQt for the Python programmer, and this book aims to fill that need.

My first book, Python GUI Programming with Tkinter, focused on the rudiments of application development using Tkinter, covering core topics such as interface design, unit testing, program architecture, and packaging. In this book, I wanted to go beyond the basics, not just teaching you how to build data-driven business forms (which so many toolkits can produce, and so many other books can teach you to write), but to explore the more exciting and unique possibilities offered by PyQt: multimedia, animation, 3D graphics, image manipulation, networking, multi-threading, and more. Of course, this book doesn't shirk the business side of things either, with solid coverage of data entry forms, SQL databases, and charting.

There are two kinds of authors who write technical books. The first is the absolute expert, with infallible authority and encyclopedic knowledge of the topic at hand, who is able to draw on a deep understanding to produce explanations that perfectly address the learner's most pertinent needs.

The second kind of author is a mere mortal possessed of a reasonable familiarity with the basics, a willingness to research what is not known, and most importantly, a dogged determination to ensure that every statement asserted in print is the whole and correct truth. This author must be prepared to stop mid-sentence in the flow of writing to test claims in the interpreter or code editor; to spend hours reading documentation, mailing-list threads, code comments, and IRC logs in the pursuit of a more correct understanding; and to delete and rewrite large swathes of their work when a new fact reveals a fault in their original assumptions.

When I was asked to write a book on PyQt5, I could make no claims to being the first sort of author (nor can I now); while I had developed and maintained several PyQt applications both at work and in the open source world, my understanding of PyQt rarely strayed beyond the simple needs of my own code. So, I have aspired to be the second type, committing myself to diligent study and the painstaking process of sifting and distilling the tangled mass of available information into a text that might guide the aspiring GUI programmer toward mastery of PyQt.

As a proud father of five children, some of whom have a budding (if not blooming) interest in programming, I have worked these past six months to write a book that I could confidently and conscientiously put before them, should they wish to learn these skills. I hope, dear reader, that you sense in this text this parental enthusiasm for your growth and progress as we tackle this subject together.