Book Image

Python GUI Programming Cookbook, Second Edition - Second Edition

By : Burkhard Meier
Book Image

Python GUI Programming Cookbook, Second Edition - Second Edition

By: Burkhard Meier

Overview of this book

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.
Table of Contents (18 chapters)
Title Page
Credits
About the Author
About the Reviewer
www.PacktPub.com
Customer Feedback
Preface

Adding a progressbar to the GUI


In this recipe, we will add a Progressbar to our GUI. It is very easy to add a ttk.Progressbar, and we will demonstrate how to start and stop a Progressbar. This recipe will also show you how to delay the stopping of a Progressbar and how to run it in a loop.

Note

Progressbar is typically used to show the current status of a long-running process. 

Getting ready

We will add the progressbar to Tab 2 of the GUI that we developed in the previous recipe: Creating tooltips using Python.

How to do it…

First, we add four buttons into LabelFrame on Tab 2, replacing the labels that were there before. We set the Labelframe text property to ProgressBar.

We then place a ttk.Progressbar widget below all other widgets on Tab 2 and align this new widget with the other widgets.

Our GUI now looks as follows:

GUI_progressbar.py

We connect each of our four new buttons to a new callback function, which we assign to their command property:

Note

Clicking the Run Progressbar button will run...