In this iteration, we add tooltip also named the Balloon widget to all the buttons in our player.
A tooltip is a small popup, which shows up when you hover your mouse over the Bound widget (buttons in our case). A typical tooltip on our application would look as shown in the following screenshot:
Although core Tkinter has many useful widgets, it is far from complete. For us, the tooltip or Balloon widget is not provided as a core Tkinter widget. We, therefore, look for these widgets in what are named Tkinter extensions.
These extensions are nothing but modified Tkinter widgets to act and behave with new functionalities not offered by Tkinter.
There are literally hundreds of Tkinter extensions. In fact, we could write our own Tkinter extensions. However, some of the popular Tkinter extensions are as follows:
PMW provides the Balloon widget implementation, but it is not part of standard Tkinter library. We need to add it. To add PMW, refer to our discussion under the Mission Checklist section. Once added, you need to import PMW into your namespace, as follows (see Code 5.07 main-gui.py):
import Pmw
We then instantiate the Balloon widget within the mainloop from our __init__
method as follows:
self.balloon = Pmw.Balloon(self.root)
Finally, we bind the Balloon widget to each of the button widgets in our player. We will not reproduce the code for each button. However, the format is as follows:
balloon.bind(name of widget, 'Description for the balloon')
So our Add File button would have a balloon binding as follows:
self.balloon.bind(add_filebtn, 'Add New File')
We add similar code for each button in 5.07 main-gui.py.
Before we end this iteration, let us add a title to our player and add a title bar icon as well, as follows:
self.root.title('Media Player') self.root.iconbitmap('../icons/mp.ico')
This completes the iteration. We added Balloon tooltips to our player buttons using PMW Tkinter extension.
Most importantly, we got to know about Tkinter extensions and when to use them.
When you come across a widget implementation need that is not available as a core widget, try looking for implementations of it in PMW or Tix. If you don't find one that suits your need, search the Internet for some other Tkinter extension.
If you still don't find your desired implementation, try out WCK, which lets you implement all types of custom widgets. However, note that WCK is not under active development for long.
3.133.156.251