Mastering GUI Programming with Python
Develop impressive cross-platform GUI applications
with PyQt
Alan D. Moore
BIRMINGHAM - MUMBAI
Mastering GUI Programming with Python
Copyright 2019 Packt Publishing
All rights reserved. No part of this book may be reproduced, stored in a retrieval system, or transmitted in any form or by any means, without the prior written permission of the publisher, except in the case of brief quotations embedded in critical articles or reviews.
Every effort has been made in the preparation of this book to ensure the accuracy of the information presented. However, the information contained in this book is sold without warranty, either express or implied. Neither the author, nor Packt Publishing or its dealers and distributors, will be held liable for any damages caused or alleged to have been caused directly or indirectly by this book.
Packt Publishing has endeavored to provide trademark information about all of the companies and products mentioned in this book by the appropriate use of capitals. However, Packt Publishing cannot guarantee the accuracy of this information.
Commissioning Editor: Richa Tripathi
Acquisition Editor: Shriram Shekhar
Content Development Editor: Digvijay Bagul
Technical Editor: Abin Sebastian
Copy Editor: Safis Editing
Project Coordinator: Prajakta Naik
Proofreader: Safis Editing
Indexer: Pratik Shirodkar
Graphics Coordinator: Jisha Chirayil
Production Coordinator: Aparna Bhagat
First published: May 2019
Production reference: 1230519
Published by Packt Publishing Ltd.
Livery Place
35 Livery Street
Birmingham
B3 2PB, UK.
ISBN 978-1-78961-290-5
www.packtpub.com
To my childrenmay you be inspired to create, be diligent to create well, and be bold enough
to share your creations confidently with the world.
Alan D. Moore
mapt.io
Mapt is an online digital library that gives you full access to over 5,000 books and videos, as well as industry leading tools to help you plan your personal development and advance your career. For more information, please visit our website.
Why subscribe?
Spend less time learning and more time coding with practical eBooks and Videos from over 4,000 industry professionals
Improve your learning with Skill Plans built especially for you
Get a free eBook or video every month
Mapt is fully searchable
Copy and paste, print, and bookmark content
Packt.com
Did you know that Packt offers eBook versions of every book published, with PDF and ePub files available? You can upgrade to the eBook version at www.packt.com and as a print book customer, you are entitled to a discount on the eBook copy. Get in touch with us at customercare@packtpub.com for more details.
At www.packt.com , you can also read a collection of free technical articles, sign up for a range of free newsletters, and receive exclusive discounts and offers on Packt books and eBooks.
Contributors
About the author
Alan D. Moore is a data analyst and software developer who has been solving problems with Python since 2006. He's developed both open source and private code using frameworks such as Django, Flask, Qt, and Tkinter, and contributes to various open source Python and JavaScript projects. Alan is the author of Python GUI Programming with Tkinter.
About the reviewer
Chankey Pathak is a data scientist from India. He's the author of a Python API for high-frequency trading with Morgan Stanley. He has worked with Citadel, Sophos, and Proofpoint in the past. He's also well-known in the Perl community for his contributions. He is an open source contributor and loves Linux.
Packt is searching for authors like you
If you're interested in becoming an author for Packt, please visit authors.packtpub.com and apply today. We have worked with thousands of developers and tech professionals, just like you, to help them share their insight with the global tech community. You can make a general application, apply for a specific hot topic that we are recruiting an author for, or submit your own idea.
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.
Next page