Book Image

Python GUI Programming Cookbook

By : Burkhard Meier
Book Image

Python GUI Programming Cookbook

By: Burkhard Meier

Overview of this book

Table of Contents (18 chapters)
Python GUI Programming Cookbook
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Creating reusable GUI components


We are creating reusable GUI components using Python.

In this recipe, we will keep it simple by moving our ToolTip class into its own module. Next, we will import and use it for displaying tooltips over several widgets of our GUI.

Getting ready

We are building on our previous code.

How to do it...

We will start by breaking out our ToolTip class into a separate Python module. We will slightly enhance it to pass in the control widget and the tooltip text we wish to display when we hover the mouse over the control.

We create a new Python module and place the ToolTip class code into it and then import this module into our primary module.

We then reuse the imported ToolTip class by creating several tooltips, which can be seen when hovering the mouse over several of our GUI widgets.

Refactoring our common ToolTip class code out into its own module helps us to reuse this code from other modules. Instead of copy/paste/modify we use the DRY principle and our common code is...