Book Image

Python GUI Programming Cookbook - Third Edition

By : Burkhard Meier
Book Image

Python GUI Programming Cookbook - Third Edition

By: Burkhard Meier

Overview of this book

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.
Table of Contents (13 chapters)

Threads and Networking

In this chapter, we will extend the functionality of our Python GUI using threads, queues, and network connections.

A tkinter GUI is a single-threaded application. Every function that involves sleep or wait time has to be called in a separate thread; otherwise, the tkinter GUI freezes.

When we run our Python GUI, in Windows Task Manager, we can see that a new python.exe process has been launched. When we give our Python GUI a .pyw extension, then the process created will be python.pyw, which can be seen in Task Manager as well.

When a process is created, the process automatically creates a main thread to run our application. This is called a single-threaded application.

Single-threaded processes contain the execution of instructions in a single sequence. In other words, one command is processed at a time.

For our Python GUI, a single-threaded application...