Joshua M. Willman
Beginning PyQt
A Hands-on Approach to GUI Programming
Joshua M. Willman
Hampton, VA, USA
Any source code or other supplementary material referenced by the author in this book is available to readers on GitHub via the books product page, located at www.apress.com/978-1-4842-5856-9 . For more detailed information, please visit http://www.apress.com/source-code .
ISBN 978-1-4842-5856-9 e-ISBN 978-1-4842-5857-6
https://doi.org/10.1007/978-1-4842-5857-6
Joshua M. Willman 2020
Standard Apress
The use of general descriptive names, registered names, trademarks, service marks, etc. in this publication does not imply, even in the absence of a specific statement, that such names are exempt from the relevant protective laws and regulations and therefore free for general use.
The publisher, the authors and the editors are safe to assume that the advice and information in this book are believed to be true and accurate at the date of publication. Neither the publisher nor the authors or the editors give a warranty, expressed or implied, with respect to the material contained herein or for any errors or omissions that may have been made. The publisher remains neutral with regard to jurisdictional claims in published maps and institutional affiliations.
Distributed to the book trade worldwide by Springer Science+Business Media New York, 1 New York Plaza, New York, NY 10004. Phone 1-800-SPRINGER, fax (201) 348-4505, e-mail orders-ny@springer-sbm.com, or visit www.springeronline.com. Apress Media, LLC is a California LLC and the sole member (owner) is Springer Science + Business Media Finance Inc (SSBM Finance Inc). SSBM Finance Inc is a Delaware corporation.
To my daughter, Kalani.
Pursue what inspires you.
Introduction
Just getting started is more important than anything else. Coding a graphical user interface (GUI) can be thought of as a combination between programming and graphic design skills. An awareness of a users needs is crucial for both usability and graphical appearance. Programming a GUI is often a matter of finding the right component, referred to as widgets, to complete a task, and then applying the necessary programming skills to make them operational.
In this book, we will see how to use the Python programming language, along with the PyQt5 toolkit , to create GUIs. With PyQt5, many of the components are already created for you. However, if you ever find yourself needing a component that does not exist, with PyQt5 you can always make your own custom widgets and classes, as well.
If this is your first time creating GUIs at all, then my recommendation is to follow along withChaptersto get your bearings with PyQt. Many of the key concepts and classes that you will use for basic interfaces can be found there, including creating a window for arranging widgets, making components that are interactive and can communicate with one another and with the information stored on your computer, layout management, setting up the menu system, and manipulating a GUIs appearance.
In the remaining chapters, we will begin looking at more specific examples: looking at Qt Designer for simplifying the GUI design process inChapter.
There are also two appendices,Appendix Awhich gives extra information about PyQt classes andAppendix Bfor refreshing your knowledge about Python.
No one chapter has all the tools you will need in it. Widgets and classes are spread throughout the book, helping you to learn and apply what you have learned as you go. Nor is every one of PyQts classes covered within these pages. Learning is an ongoing process, and sometimes having to do a bit of extra searching will help ideas better stick in your mind.
Acknowledgments
Writing this book has truly been an eye-opening experience, and I owe thanks to those who have helped me reach this point in my life.
I want to begin by thanking those individuals who helped me to take a good, hard look at my life.
To Joyce Corriere, your lessons and kindness all those years ago have inspired me to this day.
Thank you to Professor Rong Xiong () for giving me the chance to pursue my dreams and to get my life back on track.
I owe a debt of gratitude to Lingyan Xu () and Melody for their laughs and support during some of the toughest times.
When I first started learning Python and PyQt a few years back, I had no idea where to begin. A big thanks to the Python community and to Jan Bodnar at ZetCode for giving me the tools to get started in creating my own applications.
Thank you so much to Apress editorial for the serendipitous e-mail that began this whole journey just as I was researching ways to write a book.
A very immense thank you must be given to my Coordinating Editor, Divya Modi, for being patient and positively stoic with me all of the times the deadlines flew past.
Thanks to my mother, Valorie, and my sisters, Teesha and Jazzmin, for all of the support you have given me.
Words cannot express how deeply grateful I am to my wife, Evelyn, who has been the most patient of all during this time, listening to my incessant rambling about ideas, and who helped me realize that I cannot put everything into one book.
To Kalani, your laughs have been an enormous uplift.
Lastly, thank you to the readers. I hope the ideas found within this book can help you in some way.
Table of Contents
About the Author
Joshua M. Willman
began using Python in 2015, when his first task was to build neural networks using machine learning libraries, including Keras and TensorFlow, for image classification. While creating large image datasets for his research, he needed to build a GUI that would simplify the workload and labeling process, which introduced him to PyQt. He currently works as a Python developer and instructor, designing courses to help others learn about coding in Python for game development, AI and machine learning, and programming using microcontrollers. More recently, he set up the site RedHuli to explore his and others interests in using Python and programming for creative purposes.
About the Technical Reviewer
Lentin Joseph
is an author and robotics entrepreneur from India. He runs a robotics software company called Qbotics Labs in India. He has 9 years of experience in the robotics domain primarily in ROS, OpenCV, and PCL.
He has authored eight books in ROS, namely,Learning Robotics Using Python1st and 2nd edition,Mastering ROS for Robotics Programming1st and 2nd edition,ROS Robotics Projects,Robot Operating System for Absolute Beginners, andROS Programming.
He pursed a masters degree in robotics from India and also did research at Robotics Institute, CMU, USA. He is also a TEDx speaker.