Python GUI Programming Cookbook - Third Edition

Book description

Over 90 recipes to help you develop widgets, forms, layouts, charts, and much more using the latest features of Python 3

Key Features

  • Use object-oriented programming to develop impressive GUIs in Python
  • Create interesting charts to visually represent data using Matplotlib
  • Develop GUIs with the latest versions of tkinter, PyQt5, and wxPython frameworks

Book Description

Python is a multi-domain, interpreted programming language that is easy to learn and implement. With its wide support for frameworks to develop GUIs, you can build interactive and beautiful GUI-based applications easily using Python. This third edition of Python GUI Programming Cookbook follows a task-based approach to help you create effective GUIs with the smallest amount of code. Every recipe in this book builds upon the last to create an entire, real-life GUI application. These recipes also help you solve problems that you might encounter while developing GUIs. This book mainly focuses on using Python's built-in tkinter GUI framework. You'll learn how to create GUIs in Python using simple programming styles and object-oriented programming (OOP). As you add more widgets and expand your GUI, you will learn how to connect to networks, databases, and graphical libraries that greatly enhance the functionality of your GUI. You'll also learn how to use threading to ensure that your GUI doesn't become unresponsive. Toward the end, you'll learn about the versatile PyQt GUI framework, which comes along with its own visual editor that allows you to design GUIs using drag and drop features. By the end of the book, you'll be an expert in designing Python GUIs and be able to develop a variety of GUI applications with ease.

What you will learn

  • Create amazing GUIs with Python's built-in tkinter module
  • Customize GUIs using layout managers to arrange GUI widgets
  • Advance from the typical waterfall coding style to an OOP style using Python
  • Develop beautiful charts using the free Matplotlib Python module
  • Use threading in a networked environment to make GUIs responsive
  • Discover ways to connect GUIs to a MySQL database
  • Understand how unit tests can be created and internationalize GUI
  • Delve into the world of GUI creation using PyQt5

Who this book is for

If you're a programmer or developer looking to enhance your Python skills by writing powerful GUI applications, this book is for you. Familiarity with the Python programming language is necessary to get the most out of the book.

Table of contents

  1. Title Page
  2. Copyright and Credits
    1. Python GUI Programming Cookbook Third Edition
  3. About Packt
    1. Why subscribe?
  4. Contributors
    1. About the author
    2. About the reviewers
    3. Packt is searching for authors like you
  5. Preface
    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. Download the color images
      3. Conventions used
    4. Sections
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
      5. See also
    5. Get in touch
      1. Reviews
  6. Creating the GUI Form and Adding Widgets
    1. Creating our first Python GUI
      1. Getting ready
      2. How to do it...
      3. How it works...
    2. Preventing the GUI from being resized
      1. Getting ready
      2. How to do it...
      3. How it works...
    3. Adding a label to the GUI form
      1. Getting ready
      2. How to do it...
      3. How it works...
    4. Creating buttons and changing their text attributes
      1. Getting ready
      2. How to do it...
      3. How it works...
    5. Creating textbox widgets
      1. Getting ready
      2. How to do it...
      3. How it works...
    6. Setting the focus to a widget and disabling widgets
      1. Getting ready
      2. How to do it...
      3. How it works...
    7. Creating combobox widgets
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
    8. Creating a check button with different initial states
      1. Getting ready
      2. How to do it...
      3. How it works...
    9. Using radio button widgets
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
    10. Using scrolled text widgets
      1. Getting ready
      2. How to do it...
      3. How it works...
    11. Adding several widgets in a loop
      1. Getting ready
      2. How to do it...
      3. How it works...
  7. Layout Management
    1. Arraning several labels within a label frame widget
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. See also...
    2. Using padding to add space around widgets
      1. Getting ready
      2. How to do it...
      3. How it works...
    3. Dynamically expanding the GUI using widgets
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
    4. Aligning GUI widgets by embedding frames within frames
      1. Getting ready
      2. How to do it...
      3. How it works...
    5. Creating menu bars
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
    6. Creating tabbed widgets
      1. Getting ready
      2. How to do it...
      3. How it works...
    7. Using the grid layout manager
      1. Getting ready...
      2. How to do it...
      3. How it works...
  8. Look and Feel Customization
    1. Creating message boxes – information, warning, and error
      1. Getting ready
      2. How to do it...
      3. How it works...
    2. How to create independent message boxes
      1. Getting ready
      2. How to do it...
      3. How it works...
    3. How to create the title of a tkinter window form
      1. Getting ready
      2. How to do it...
      3. How it works...
    4. Changing the icon of the main root window
      1. Getting ready
      2. How to do it...
      3. How it works...
    5. Using a spin box control
      1. Getting ready
      2. How to do it...
      3. How it works...
    6. Applying relief – the sunken and raised appearance of widgets
      1. Getting ready
      2. How to do it...
      3. How it works...
    7. Creating tooltips using Python
      1. Getting ready
      2. How to do it...
      3. How it works...
    8. Adding Progressbar to the GUI
      1. Getting ready
      2. How to do it...
      3. How it works...
    9. How to use the canvas widget
      1. Getting ready
      2. How to do it...
      3. How it works...
  9. Data and Classes
    1. How to use StringVar()
      1. Getting ready
      2. How to do it...
      3. How it works...
    2. How to get data from a widget
      1. Getting ready
      2. How to do it...
      3. How it works...
    3. Using module-level global variables
      1. Getting ready
      2. How to do it...
      3. How it works...
    4. How coding in classes can improve the GUI
      1. Getting ready
      2. How to do it...
      3. How it works...
    5. Writing callback functions
      1. Getting ready
      2. How to do it...
      3. How it works...
    6. Creating reusable GUI components
      1. Getting ready
      2. How to do it...
      3. How it works...
  10. Matplotlib Charts
    1. Installing Matplotlib using pip with the .whl extension
      1. Getting ready
      2. How to do it...
      3. How it works...
    2. Creating our first chart
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
    3. Placing labels on charts
      1. Getting ready
      2. How to do it...
      3. How it works...
    4. How to give the chart a legend
      1. Getting ready
      2. How to do it...
      3. How it works...
    5. Scaling charts
      1. Getting ready
      2. How to do it...
      3. How it works...
    6. Adjusting the scale of charts dynamically
      1. Getting ready
      2. How to do it...
      3. How it works...
  11. Threads and Networking
    1. How to create multiple threads
      1. Getting ready
      2. How to do it...
      3. How it works...
    2. Starting a thread
      1. Getting ready
      2. How to do it...
      3. How it works...
    3. Stopping a thread
      1. Getting ready
      2. How to do it...
      3. How it works...
    4. How to use queues
      1. Getting ready
      2. How to do it...
      3. How it works...
    5. Passing queues among different modules
      1. Getting ready
      2. How to do it...
      3. How it works...
    6. Using dialog widgets to copy files to your network
      1. Getting ready
      2. How to do it...
      3. How it works...
    7. Using TCP/IP to communicate via networks
      1. Getting ready
      2. How to do it...
      3. How it works...
    8. Using urlopen to read data from websites
      1. Getting ready
      2. How to do it...
      3. How it works...
  12. Storing Data in Our MySQL Database via Our GUI
    1. Installing and connecting to a MySQL server from Python
      1. Getting ready
      2. How to do it...
      3. How it works...
    2. Configuring the MySQL database connection
      1. Getting ready
      2. How to do it...
      3. How it works...
    3. Designing the Python GUI database
      1. Getting ready
      2. How to do it...
      3. How it works...
    4. Using the SQL INSERT command
      1. Getting ready
      2. How to do it...
      3. How it works...
    5. Using the SQL UPDATE command
      1. Getting ready
      2. How to do it...
      3. How it works...
    6. Using the SQL DELETE command
      1. Getting ready
      2. How to do it...
      3. How it works...
    7. Storing and retrieving data from our MySQL database
      1. Getting ready
      2. How to do it...
      3. How it works...
    8. Using MySQL Workbench
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
  13. Internationalization and Testing
    1. Displaying widget text in different languages
      1. Getting ready
      2. How to do it...
      3. How it works...
    2. Changing the entire GUI language all at once
      1. Getting ready
      2. How to do it...
      3. How it works...
    3. Localizing the GUI
      1. Getting ready
      2. How to do it...
      3. How it works...
    4. Preparing the GUI for internationalization
      1. Getting ready
      2. How to do it...
      3. How it works...
    5. How to design a GUI in an agile fashion
      1. Getting ready
      2. How to do it...
      3. How it works...
    6. Do we need to test the GUI code?
      1. Getting ready
      2. How to do it...
      3. How it works...
    7. Setting debug watches
      1. Getting ready
      2. How to do it...
      3. How it works...
    8. Configuring different debug output levels
      1. Getting ready
      2. How to do it...
      3. How it works...
    9. Creating self-testing code using Python's __main__ section
      1. Getting ready
      2. How to do it...
      3. How it works...
    10. Creating robust GUIs using unit tests
      1. Getting ready
      2. How to do it...
      3. How it works...
    11. How to write unit tests using the Eclipse PyDev IDE
      1. Getting ready
      2. How to do it...
      3. How it works...
  14. Extending Our GUI with the wxPython Library
    1. Installing the wxPython library
      1. Getting ready
      2. How to do it...
      3. How it works...
    2. Creating our GUI in wxPython
      1. Getting ready
      2. How to do it...
      3. How it works...
    3. Quickly adding controls using wxPython
      1. Getting ready
      2. How to do it...
      3. How it works...
    4. Trying to embed a main wxPython app in a main tkinter app
      1. Getting ready
      2. How to do it...
      3. How it works...
    5. Trying to embed our tkinter GUI code into wxPython
      1. Getting ready
      2. How to do it...
      3. How it works...
    6. Using Python to control two different GUI frameworks
      1. Getting ready
      2. How to do it...
      3. How it works...
    7. Communicating between the two connected GUIs
      1. Getting ready
      2. How to do it...
      3. How it works...
  15. Building GUIs with PyQt5
    1. Installing PyQt5
      1. Getting ready
      2. How to do it...
      3. How it works...
    2. Installing the PyQt5 Designer tool
      1. Getting ready
      2. How to do it...
      3. How it works...
    3. Writing our first PyQt5 GUI
      1. Getting ready
      2. How to do it...
      3. How it works...
    4. Changing the title of the GUI
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
    5. Refactoring our code into object-oriented programming
      1. Getting ready
      2. How to do it...
      3. How it works...
    6. Inheriting from QMainWindow
      1. Getting ready
      2. How to do it...
      3. How it works...
    7. Adding a status bar widget
      1. Getting ready
      2. How to do it...
      3. How it works...
    8. Adding a menu bar widget
      1. Getting ready
      2. How to do it...
      3. How it works...
    9. Starting the PyQt5 Designer tool
      1. Getting ready
      2. How to do it...
      3. How it works...
    10. Previewing the form within the PyQt5 Designer
      1. Getting ready
      2. How to do it...
      3. How it works...
    11. Saving the PyQt5 Designer form
      1. Getting ready
      2. How to do it...
      3. How it works...
    12. Converting Designer .ui code into .py code
      1. Getting ready
      2. How to do it...
      3. How it works...
    13. Understanding the converted Designer code
      1. Getting ready
      2. How to do it...
      3. How it works...
    14. Building a modular GUI design
      1. Getting ready
      2. How to do it...
      3. How it works...
    15. Adding another menu item to our menu bar
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
    16. Connecting functionality to the Exit menu item
      1. Getting ready
      2. How to do it...
      3. How it works...
    17. Adding a Tab Widget via the Designer
      1. Getting ready
      2. How to do it...
      3. How it works...
    18. Using layouts in the Designer
      1. Getting ready
      2. How to do it...
      3. How it works...
    19. Adding buttons and labels in the Designer
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
  16. Best Practices
    1. Avoiding spaghetti code
      1. Getting ready
      2. How to do it...
      3. How it works...
    2. Using __init__ to connect modules
      1. Getting ready
      2. How to do it...
      3. How it works...
    3. Mixing fall-down and OOP coding
      1. Getting ready
      2. How to do it...
      3. How it works...
    4. Using a code naming convention
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
    5. When not to use OOP
      1. Getting ready
      2. How to do it...
      3. How it works...
    6. How to use design patterns successfully
      1. Getting ready
      2. How to do it...
      3. How it works...
    7. Avoiding complexity
      1. Getting ready
      2. How to do it...
      3. How it works...
    8. GUI design using multiple notebooks
      1. Getting ready
      2. How to do it...
      3. How it works...
  17. Other Books You May Enjoy
    1. Leave a review - let other readers know what you think

Product information

  • Title: Python GUI Programming Cookbook - Third Edition
  • Author(s): Burkhard Meier
  • Release date: October 2019
  • Publisher(s): Packt Publishing
  • ISBN: 9781838827540