Python GUI Programming Cookbook - Second Edition

Book description

Master over 80 object-oriented recipes to create amazing GUIs in Python and revolutionize your applications today

About This Book

  • Use object-oriented programming to develop amazing GUIs in Python
  • Create a working GUI project as a central resource for developing your Python GUIs
  • Easy-to-follow recipes to help you develop code using the latest released version of Python

Who This Book Is For

This book is for intermediate Python programmers who wish to enhance their Python skills by writing powerful GUIs in Python. As Python is such a great and easy to learn language, this book is also ideal for any developer with experience of other languages and enthusiasm to expand their horizon.

What You Will Learn

  • Create the GUI Form and add widgets
  • Arrange the widgets using layout managers
  • Use object-oriented programming to create GUIs
  • Create Matplotlib charts
  • Use threads and talking to networks
  • Talk to a MySQL database via the GUI
  • Perform unit-testing and internationalizing the GUI
  • Extend the GUI with third-party graphical libraries
  • Get to know the best practices to create GUIs

In Detail

Python is a multi-domain, interpreted programming language. It is a widely used general-purpose, high-level programming language. It is often used as a scripting language because of its forgiving syntax and compatibility with a wide variety of different eco-systems. Python GUI Programming Cookbook follows a task-based approach to help you create beautiful and very effective GUIs with the least amount of code necessary.

This book will guide you through the very basics of creating a fully functional GUI in Python with only a few lines of code. Each and every recipe adds more widgets to the GUIs we are creating. While the cookbook recipes all stand on their own, there is a common theme running through all of them. As our GUIs keep expanding, using more and more widgets, we start to talk to networks, databases, and graphical libraries that greatly enhance our GUI’s functionality. This book is what you need to expand your knowledge on the subject of GUIs, and make sure you’re not missing out in the long run.

Style and approach

This programming cookbook consists of standalone recipes, and this approach makes it unique.. While each recipe explains a certain concept, throughout the book you’ll build a more and more advanced GUI, recipe after recipe. In some of the advanced topics, we simply create a new GUI in order to explore these topics in depth.

Downloading the example code for this book. You can download the example code files for all Packt books you have purchased from your account at http://www.PacktPub.com. If you purchased this book elsewhere, you can visit http://www.PacktPub.com/support and register to have the code file.

Publisher resources

Download Example Code

Table of contents

  1. Credits
  2. Preface
    1. What this book covers
    2. What you need for this book
    3. Who this book is for
    4. Conventions
    5. Reader feedback
    6. Customer support
      1. Downloading the example code
      2. Downloading the color images of this book
      3. Errata
      4. Piracy
      5. Questions
  3. Creating the GUI Form and Adding Widgets
    1. Introduction
    2. Creating our first Python GUI
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
    3. Preventing the GUI from being resized
      1. Getting ready
      2. How to do it...
      3. How it works...
    4. Adding a label to the GUI form
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
    5. Creating buttons and changing their text property
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
    6. Text box widgets
      1. Getting ready
      2. How to do it...
      3. How it works...
    7. Setting the focus to a widget and disabling widgets
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
    8. Combo box widgets
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
    9. Creating a check button with different initial states
      1. Getting ready
      2. How to do it...
      3. How it works...
    10. Using radio button widgets
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
    11. Using scrolled text widgets
      1. Getting ready
      2. How to do it...
      3. How it works...
    12. Adding several widgets in a loop
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
  4. Layout Management
    1. Introduction
    2. Arranging several labels within a label frame widget
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
    3. Using padding to add space around widgets
      1. Getting ready
      2. How to do it...
      3. How it works...
    4. How widgets dynamically expand the GUI
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
    5. Aligning the GUI widgets by embedding frames within frames
      1. Getting ready
      2. How to do it...
      3. How it works...
    6. Creating menu bars
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
    7. Creating tabbed widgets
      1. Getting ready
      2. How to do it...
      3. How it works...
    8. Using the grid layout manager
      1. Getting ready...
      2. How to do it...
      3. How it works...
  5. Look and Feel Customization
    1. Introduction
    2. Creating message boxes - information, warning, and error
      1. Getting ready
      2. How to do it...
      3. How it works...
    3. How to create independent message boxes
      1. Getting ready
      2. How to do it...
      3. How it works...
    4. How to create the title of a tkinter window form
      1. Getting ready
      2. How to do it...
      3. How it works...
    5. Changing the icon of the main root window
      1. Getting ready
      2. How to do it...
      3. How it works...
    6. Using a spin box control
      1. Getting ready
      2. How to do it...
      3. How it works...
    7. Relief, sunken and raised appearance of widgets
      1. Getting ready
      2. How to do it...
      3. How it works...
    8. Creating tooltips using Python
      1. Getting ready
      2. How to do it...
      3. How it works...
    9. Adding a progressbar to the GUI
      1. Getting ready
      2. How to do it...
      3. How it works...
    10. How to use the canvas widget
      1. Getting ready
      2. How to do it...
      3. How it works...
  6. Data and Classes
    1. Introduction
    2. How to use StringVar()
      1. Getting ready
      2. How to do it...
      3. How it works...
    3. How to get data from a widget
      1. Getting ready
      2. How to do it...
      3. How it works...
    4. Using module-level global variables
      1. Getting ready
      2. How to do it...
      3. How it works...
    5. How coding in classes can improve the GUI
      1. Getting ready
      2. How to do it...
      3. How it works...
    6. Writing callback functions
      1. Getting ready
      2. How to do it...
      3. How it works...
    7. Creating reusable GUI components
      1. Getting ready
      2. How to do it...
      3. How it works...
  7. Matplotlib Charts
    1. Introduction
    2. Creating beautiful charts using Matplotlib
      1. Getting ready
      2. How to do it...
      3. How it works...
    3. Installing Matplotlib using pip with whl extension
      1. Getting ready
      2. How to do it...
      3. How it works...
    4. Creating our first chart
      1. Getting ready
      2. How to do it...
      3. How it works...
    5. Placing labels on charts
      1. Getting ready
      2. How to do it...
      3. How it works...
    6. How to give the chart a legend
      1. Getting ready
      2. How to do it...
      3. How it works...
    7. Scaling charts
      1. Getting ready
      2. How to do it...
      3. How it works...
    8. Adjusting the scale of charts dynamically
      1. Getting ready
      2. How to do it...
      3. How it works...
  8. Threads and Networking
    1. Introduction
    2. How to create multiple threads
      1. Getting ready
      2. How to do it...
      3. How it works...
    3. Starting a thread
      1. Getting ready
      2. How to do it...
      3. How it works...
    4. Stopping a thread
      1. Getting ready
      2. How to do it...
      3. How it works...
    5. How to use queues
      1. Getting ready
      2. How to do it...
      3. How it works...
    6. Passing queues among different modules
      1. Getting ready
      2. How to do it...
      3. How it works...
    7. Using dialog widgets to copy files to your network
      1. Getting ready
      2. How to do it...
      3. How it works...
    8. Using TCP/IP to communicate via networks
      1. Getting ready
      2. How to do it...
      3. How it works...
    9. Using urlopen to read data from websites
      1. Getting ready
      2. How to do it...
      3. How it works...
  9. Storing Data in our MySQL Database via our GUI
    1. Introduction
    2. Installing and connecting to a MySQL server from Python
      1. Getting ready
      2. How to do it...
      3. How it works...
    3. Configuring the MySQL database connection
      1. Getting ready
      2. How to do it...
      3. How it works...
    4. Designing the Python GUI database
      1. Getting ready
      2. How to do it...
      3. How it works...
    5. Using the SQL INSERT command
      1. Getting ready
      2. How to do it...
      3. How it works...
    6. Using the SQL UPDATE command
      1. Getting ready
      2. How to do it...
      3. How it works...
    7. Using the SQL DELETE command
      1. Getting ready
      2. How to do it...
      3. How it works...
    8. Storing and retrieving data from our MySQL database
      1. Getting ready
      2. How to do it...
      3. How it works...
    9. Using the MySQL workbench
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
  10. Internationalization and Testing
    1. Introduction
    2. Displaying widget text in different languages
      1. Getting ready
      2. How to do it...
      3. How it works...
    3. Changing the entire GUI language, all at once
      1. Getting ready
      2. How to do it...
      3. How it works...
    4. Localizing the GUI
      1. Getting ready
      2. How to do it...
      3. How it works...
    5. Preparing the GUI for internationalization
      1. Getting ready
      2. How to do it...
      3. How it works...
    6. How to design a GUI in an agile fashion
      1. Getting ready
      2. How to do it...
      3. How it works...
    7. Do we need to test the GUI code?
      1. Getting ready
      2. How to do it...
      3. How it works...
    8. Setting debug watches
      1. Getting ready
      2. How to do it...
      3. How it works...
    9. Configuring different debug output levels
      1. Getting ready
      2. How to do it...
      3. How it works...
    10. Creating self-testing code using Python's __main__ section
      1. Getting ready
      2. How to do it...
      3. How it works...
    11. Creating robust GUIs using unit tests
      1. Getting ready
      2. How to do it...
      3. How it works...
    12. How to write unit tests using the Eclipse PyDev IDE
      1. Getting ready
      2. How to do it...
      3. How it works...
  11. Extending Our GUI with the wxPython Library
    1. Introduction
    2. Installing the wxPython library
      1. Getting ready
      2. How to do it...
      3. How it works...
    3. Creating our GUI in wxPython
      1. Getting ready
      2. How to do it...
      3. How it works...
    4. Quickly adding controls using wxPython
      1. Getting ready
      2. How to do it...
      3. How it works...
    5. Trying to embed a main wxPython app in a main tkinter app
      1. Getting ready
      2. How to do it...
      3. How it works...
    6. Trying to embed our tkinter GUI code into wxPython
      1. Getting ready
      2. How to do it...
      3. How it works...
    7. Using Python to control two different GUI frameworks
      1. Getting ready
      2. How to do it...
      3. How it works...
    8. Communicating between the two connected GUIs
      1. Getting ready
      2. How to do it...
      3. How it works...
  12. Creating Amazing 3D GUIs with PyOpenGL and PyGLet
    1. Introduction
    2. PyOpenGL transforms our GUI
      1. Getting ready
      2. How to do it...
      3. How it works...
    3. Our GUI in 3D!
      1. Getting ready
      2. How to do it...
      3. How it works...
    4. Using bitmaps to make our GUI pretty
      1. Getting ready
      2. How to do it...
      3. How it works...
    5. PyGLet transforms our GUI easier than PyOpenGL
      1. How to do it...
      2. How it works...
    6. Our GUI in amazing colors
      1. Getting ready
      2. How to do it...
      3. How it works...
    7. OpenGL animation
      1. Getting ready
      2. How to do it...
      3. How it works...
    8. Creating a slide show using tkinter
      1. Getting ready
      2. How to do it...
      3. How it works...
  13. Best Practices
    1. Introduction
    2. Avoiding spaghetti code
      1. Getting ready
      2. How to do it...
      3. How it works...
    3. Using __init__ to connect modules
      1. Getting ready
      2. How to do it...
      3. How it works...
    4. Mixing fall-down and OOP coding
      1. Getting ready
      2. How to do it...
      3. How it works...
    5. Using a code naming convention
      1. Getting ready
      2. How to do it...
      3. How it works...
    6. When not to use OOP
      1. Getting ready
      2. How to do it...
      3. How it works...
    7. How to use design patterns successfully
      1. Getting ready
      2. How to do it...
      3. How it works...
    8. Avoiding complexity
      1. Getting ready
      2. How to do it...
      3. How it works...
    9. GUI design using multiple notebooks
      1. Getting ready
      2. How to do it...
      3. How it works...

Product information

  • Title: Python GUI Programming Cookbook - Second Edition
  • Author(s): Burkhard A. Meier
  • Release date: May 2017
  • Publisher(s): Packt Publishing
  • ISBN: 9781787129450