Python GUI Programming - A Complete Reference Guide

Python GUI Programming - A Complete Reference Guide

Read it now on the O’Reilly learning platform with a 10-day free trial.

O’Reilly members get unlimited access to books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.

Book description

Explore Python's GUI frameworks and create visually stunning and feature-rich applications

Key Features

Book Description

A responsive graphical user interface (GUI) helps you interact with your application, improves user experience, and enhances the efficiency of your applications. With Python, you'll have access to elaborate GUI frameworks that you can use to build interactive GUIs that stand apart from the rest.

This Learning Path begins by introducing you to Tkinter and PyQt, before guiding you through the application development process. As you expand your GUI by adding more widgets, you'll work with networks, databases, and graphical libraries that enhance its functionality. You'll also learn how to connect to external databases and network resources, test your code, and maximize performance using asynchronous programming. In later chapters, you'll understand how to use the cross-platform features of Tkinter and Qt5 to maintain compatibility across platforms. You'll be able to mimic the platform-native look and feel, and build executables for deployment across popular computing platforms.

By the end of this Learning Path, you'll have the skills and confidence to design and build high-end GUI applications that can solve real-world problems.

This Learning Path includes content from the following Packt products:

What you will learn

Who this book is for

If you're an intermediate Python programmer looking to enhance your coding skills by writing powerful GUIs in Python using PyQT and Tkinter, this is an ideal Learning Path for you. A strong understanding of the Python language is a must to grasp the concepts explained in this book.

Show and hide more Table of contents Product information

Table of contents

  1. Title Page
  2. Copyright
    1. Python GUI Programming - A Complete Reference Guide
    1. Why Subscribe?
    2. Packt.com
    1. About the Authors
    2. Packt Is Searching for Authors Like You
    1. Who This Book Is For
    2. What This Book Covers
    3. To Get the Most out of This Book
      1. Download the Example Code Files
      2. Conventions Used
      1. Reviews
      1. Introducing Tkinter and Tk
        1. Choosing Tkinter
        2. Installing Tkinter
          1. Installing Python 3 on Windows
          2. Installing Python 3 on macOS
          3. Installing Python 3 and Tkinter on Linux
          1. Using the shell mode of IDLE
          2. Using the editor mode of IDLE
          3. IDLE as a Tkinter example
          1. Creating a better Hello World Tkinter
          1. A problem at ABQ AgriLabs
            1. Assessing the problem
            2. Gathering information about the problem
            3. What you found out
              1. Information about the data being collected
              2. Information about the users of the application
              1. Contents of a simple specification
              2. Writing the ABQ data entry program specification
              1. Exploring Tkinter input widgets
              2. Grouping our fields
              3. Laying out the form
              4. Laying out the application
              1. Evaluating our technology choices
                1. Choosing a technology
                1. The Entry widget
                2. The Spinbox widget
                3. The Combobox widget
                4. The Checkbutton widget
                5. The Text widget
                6. The Button widget
                7. The LabelFrame widget
                1. Saving some time with a LabelInput class
                2. Building the form
                  1. Adding LabelFrame and other widgets
                  2. Retrieving data from our form
                  3. Resetting our form
                  1. Saving to CSV
                  1. Validating user input
                    1. Strategies to prevent data errors
                    1. Creating a DateEntry widget
                    1. Exploiting the power of multiple inheritance
                      1. A validating mixin class
                      1. Requiring data
                      2. A Date widget
                      3. A better Combobox widget
                      4. A range-limited Spinbox widget
                      5. Dynamically adjusting the Spinbox range
                      6. Updating our form
                      7. Displaying errors
                      8. Preventing form submission on error
                      1. Inserting a date
                      2. Automating Lab, Time, and Technician
                      1. Separating concerns
                        1. The MVC pattern
                          1. What is a model?
                          2. What is a view?
                          3. What is a controller?
                          1. Basic directory structure
                            1. The abq_data_entry.py file
                            2. The README.rst file
                              1. ReStructuredText
                              1. Creating the models module
                              2. Moving the widgets
                              3. Moving the views
                                1. Removing redundancy in our view logic
                                1. Running the application
                                1. A super-quick guide to using Git
                                  1. Initializing and configuring a Git repository
                                  2. Adding and committing code
                                  3. Viewing and using our commits
                                  1. Solving problems in our application
                                    1. Deciding how to address these problems
                                    1. Tkinter messagebox
                                    2. Showing the error dialogs
                                    1. Creating menus in Tkinter
                                    2. Implementing our application menu
                                    3. Showing an About dialog
                                    4. Adding the menu functionality in the controller
                                    5. Handling file selection
                                    1. Persisting settings
                                      1. Building a model for settings persistence
                                      1. Implementing read and update in the model
                                        1. Adding read and update to our model
                                          1. Implementing  get_all_records()
                                          2. Implementing  get_record()
                                          3. Adding update to save_record()
                                          1. The ttk Treeview
                                          2. Implementing our record list with Treeview
                                            1. Configuring a Treeview widget
                                            2. Adding a scrollbar
                                            3. Populating the Treeview
                                            4. Responding to record selection
                                            1. Updating __init__()
                                            2. Adding a load_record() method
                                            1. Main menu changes
                                            2. Connecting the pieces in Application
                                              1. Adding the RecordList view
                                              2. Moving the model
                                              3. Populating the record list
                                              4. Adding the new callbacks
                                              5. Cleaning up
                                              1. Working with images in Tkinter
                                                1. Tkinter PhotoImage
                                                  1. Adding the company logo
                                                  2. Setting our Window icon
                                                  1. Widget color properties
                                                    1. Using widget properties on our form
                                                    1. Styling our record list with tags
                                                    1. Giving users font options
                                                    1. Exploring a Ttk widget
                                                    2. Styling our form labels
                                                      1. Styling input widgets on error
                                                      2. Making our Spinbox a Ttk widget
                                                      3. Updating ValidatedMixin
                                                      1. Building a theme selector
                                                      1. Automated testing basics
                                                        1. A simple unit test
                                                        2. The unittest module
                                                          1. Writing a test case
                                                          2. TestCase assertion methods
                                                          3. Fixtures
                                                          4. Using Mock and patch
                                                          5. Running multiple unit tests
                                                          1. Managing asynchronous code
                                                          2. Simulating user actions
                                                            1. Specifying an event sequence
                                                            1. Testing our model
                                                              1. Testing file reading in get_all_records()
                                                              2. Testing file saving in save_record()
                                                              3. More tests
                                                              1. Unit testing the ValidatedSpinbox widget 
                                                              2. Integration testing the ValidatedSpinbox widget
                                                              3. Testing our mixin class
                                                              1. PostgreSQL
                                                                1. Installing and configuring PostgreSQL
                                                                2. Connecting with psycopg2
                                                                1. Basic SQL operations
                                                                  1. Syntax differences from Python
                                                                  2. Defining tables and inserting data
                                                                  3. Retrieving data from tables
                                                                  4. Updating rows, deleting rows, and more WHERE clauses
                                                                  5. Subqueries
                                                                  6. Joining tables
                                                                  7. Learning more
                                                                  1. Normalization
                                                                  2. The entity-relationship diagrams
                                                                  3. Assigning data types
                                                                  1. Creating our tables
                                                                    1. Creating the lookup tables
                                                                    2. The lab_checks table
                                                                    3. The plot_checks table
                                                                    1. Creating a new model
                                                                    2. Adjusting the Application class for the SQL backend
                                                                      1. Building a login window
                                                                      2. Using the login window
                                                                      3. Fixing some model incompatibilities
                                                                        1. DataRecordForm creation
                                                                        2. Fixing the open_record() method
                                                                        3. Fixing the on_save() method
                                                                        1. The data record form
                                                                        2. The record list
                                                                        1. HTTP using urllib
                                                                          1. Basic downloading with urllib.request
                                                                          2. Creating a download function
                                                                            1. Parsing XML weather data
                                                                            1. Creating the SQL table
                                                                            2. Implementing the SQLModel.add_weather_data() method
                                                                            3. Updating the SettingsModel class
                                                                            1. Installing and using requests
                                                                              1. The requests.session() fucntion
                                                                              2. The response objects
                                                                              1. Creating a test HTTP service
                                                                              2. Creating our network function
                                                                              3. Updating application
                                                                              4. Updating the models.py file
                                                                              5. Finishing up
                                                                              1. Basic concepts of FTP
                                                                              2. Creating a test FTP service
                                                                              3. Implementing the FTP upload function
                                                                                1. Listing files
                                                                                2. Retrieving files
                                                                                3. Deleting or renaming files
                                                                                1. Drawing and animation with Tkinter's Canvas
                                                                                  1. Animating Canvas objects
                                                                                    1. Creating our objects
                                                                                    2. Animating the racers
                                                                                    3. Detecting and handling a win condition
                                                                                    1. Creating the model method
                                                                                    2. Creating the graph view
                                                                                    3. Updating the application
                                                                                    1. Data model method
                                                                                    2. Creating the bubble chart view
                                                                                    3. Application method
                                                                                    1. Introduction
                                                                                      1. PyQt
                                                                                      2. Ways of creating GUI applications
                                                                                      1. Understanding the Label widget
                                                                                        1. Methods
                                                                                        1. Methods
                                                                                        1. Understanding Radio Button
                                                                                          1. Methods 
                                                                                          2. Signal description
                                                                                          1. Getting ready
                                                                                          2. How to do it.
                                                                                          3. How it works.
                                                                                          1. Getting ready
                                                                                            1. Method application
                                                                                            2. Signal description
                                                                                            1. Getting ready
                                                                                            2. How to do it.
                                                                                            3. How it works.
                                                                                            1. Introduction
                                                                                            2. Using Signal/Slot Editor
                                                                                              1. How to do it.
                                                                                              1. Getting ready
                                                                                              2. How to do it.
                                                                                              3. How it works.
                                                                                              1. How to do it.
                                                                                              2. How it works.
                                                                                              1. Getting ready
                                                                                              2. How to do it.
                                                                                              3. How it works.
                                                                                              1. Getting ready
                                                                                              2. How to do it.
                                                                                              3. How it works.
                                                                                              1. Getting ready
                                                                                              2. How to do it.
                                                                                              3. How it works.
                                                                                              1. How to do it.
                                                                                              2. How it works.
                                                                                              1. How to do it.
                                                                                              2. How it works.
                                                                                              1. Getting ready
                                                                                                1. Methods provided by the QListWidgetItem class
                                                                                                1. How to do it…
                                                                                                2. How it works.
                                                                                                1. Getting ready
                                                                                                2. How to do it…
                                                                                                3. How it works.
                                                                                                1. Getting ready
                                                                                                2. How to do it…
                                                                                                3. How it works.
                                                                                                1. Object-oriented programming
                                                                                                  1. Creating a class
                                                                                                  2. Using the built-in class attributes
                                                                                                    1. Accessing class variables in instance methods
                                                                                                      1. Instances
                                                                                                      1. How to do it.
                                                                                                      2. How it works.
                                                                                                        1. Making the application more elaborate
                                                                                                        2. Inheritance
                                                                                                          1. Types of inheritance
                                                                                                          1. Getting ready
                                                                                                          2. How to do it.
                                                                                                          3. How it works.
                                                                                                          1. Getting ready
                                                                                                          2. How to do it.
                                                                                                          3. How it works.
                                                                                                          1. Getting ready
                                                                                                          2. How to do it.
                                                                                                          3. How it works.
                                                                                                          1. Introduction
                                                                                                          2. The input dialog box
                                                                                                          3. Using the input dialog 
                                                                                                            1. How to do it.
                                                                                                            2. How it works.
                                                                                                            1. How to do it.
                                                                                                            2. How it works.
                                                                                                            1. How to do it.
                                                                                                            2. How it works.
                                                                                                            1. Getting ready
                                                                                                            2. How to do it.
                                                                                                            3. How it works.
                                                                                                            1. Understanding layouts
                                                                                                              1. Spacers
                                                                                                              1. How to do it.
                                                                                                              2. How it works.
                                                                                                              1. How to do it.
                                                                                                              2. How it works.
                                                                                                              1. How to do it.
                                                                                                              2. How it works.
                                                                                                              1. Getting ready
                                                                                                              2. How to do it.
                                                                                                              3. How it works.
                                                                                                              1. Introduction
                                                                                                              2. Creating a small browser
                                                                                                                1. How to do it.
                                                                                                                2. How it works.
                                                                                                                1. How to do it.
                                                                                                                2. How it works.
                                                                                                                1. How to do it.
                                                                                                                2. How it works.
                                                                                                                1. Getting ready
                                                                                                                2. How to do it.
                                                                                                                3. How it works.
                                                                                                                1. Getting ready
                                                                                                                2. How to do it.
                                                                                                                3. How it works.
                                                                                                                1. How to do it.
                                                                                                                2. How it works.
                                                                                                                1. How to do it…
                                                                                                                2. How it works.
                                                                                                                1. Introduction
                                                                                                                  1. Creating the cursor object
                                                                                                                  1. How to do it…
                                                                                                                  2. How it works…
                                                                                                                  1. How to do it…
                                                                                                                  2. How it works…
                                                                                                                  1. How to do it…
                                                                                                                  2. How it works…
                                                                                                                  1. How to do it…
                                                                                                                  2. How it works…
                                                                                                                  1. How to do it…
                                                                                                                  2. How it works…
                                                                                                                  1. How to do it…
                                                                                                                  2. How it works…
                                                                                                                  1. How to do it…
                                                                                                                  2. How it works…
                                                                                                                  1. How to do it…
                                                                                                                  2. How it works…
                                                                                                                  1. How to do it…
                                                                                                                  2. How it works…
                                                                                                                  1. Introduction
                                                                                                                  2. Displaying mouse coordinates
                                                                                                                    1. How to do it.
                                                                                                                    2. How it works.
                                                                                                                    1. How to do it.
                                                                                                                    2. How it works.
                                                                                                                    1. How to do it.
                                                                                                                    2. How it works.
                                                                                                                    1. How to do it.
                                                                                                                    2. How it works.
                                                                                                                    1. How to do it.
                                                                                                                    2. How it works.
                                                                                                                    1. How to do it.
                                                                                                                    2. How it works.
                                                                                                                    1. How to do it.
                                                                                                                    2. How it works.
                                                                                                                    1. How to do it.
                                                                                                                    2. How it works.
                                                                                                                    1. How to do it…
                                                                                                                    2. How it works.
                                                                                                                    1. Getting ready
                                                                                                                    2. How to do it.
                                                                                                                    3. How it works.
                                                                                                                    1. Getting ready
                                                                                                                    2. How to do it.
                                                                                                                    3. How it works.
                                                                                                                    1. Introduction
                                                                                                                      1. Implementing animation
                                                                                                                      1. How to do it.
                                                                                                                      2. How it works.
                                                                                                                      1. How to do it.
                                                                                                                      2. How it works.
                                                                                                                      1. How to do it.
                                                                                                                      2. How it works.
                                                                                                                      1. How to do it.
                                                                                                                      2. How it works.
                                                                                                                      1. Introduction
                                                                                                                      2. Finding out details of a location or a landmark
                                                                                                                        1. How to do it…
                                                                                                                        2. How it works…
                                                                                                                        1. How to do it…
                                                                                                                        2. How it works…
                                                                                                                        1. How to do it…
                                                                                                                        2. How it works…
                                                                                                                        1. How to do it…
                                                                                                                        2. How it works…
                                                                                                                        1. Leave a review - let other readers know what you think
                                                                                                                        Show and hide more

                                                                                                                        Product information

                                                                                                                        • Title: Python GUI Programming - A Complete Reference Guide
                                                                                                                        • Author(s): Alan D. Moore, B. M. Harwani
                                                                                                                        • Release date: June 2019
                                                                                                                        • Publisher(s): Packt Publishing
                                                                                                                        • ISBN: 9781838988470