Creating reusable GUI components
We will create reusable GUI components using Python. In this recipe, we will keep it simple by moving our ToolTip
class into its own module. Then, we will import and use it for displaying tooltips over several widgets of our GUI.
Getting ready
We are building our code from Chapter 3, Look and Feel Customization: GUI_tooltip.py
.
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 that 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 reuse this code from other modules. Instead of copy/paste/modify...