Creating tooltips using Python

This recipe will show us how to create ToolTips. When the user hovers the mouse over a widget, additional information will be available in the form of a ToolTip.

We will code this additional information into our GUI.

Getting ready

We are adding more useful functionality to our GUI. Surprisingly, adding a ToolTip to our controls should be simple, but it is not as simple as we wish it to be.

In order to achieve this desired functionality, we will place our ToolTip code into its own OOP class.

How to do it...

Add this class just below the import statements:

class ToolTip(object): def __init__(self, widget): self.widget = widget self.tipwindow = None self.id = None self.x = self.y = 0 def showtip(self, text): "Display text ...

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.