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