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 ...

Get Python GUI Programming Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.