O'Reilly logo

Python GUI Programming Cookbook by Burkhard A. Meier

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required