The Balloon Widget
Using a Balloon widget, you can create help-text-like labels that appear as the mouse hovers over a widget. You can also use it to create help text that appears in a status bar. Let’s look at a very simple example, then go over the relevant options and methods:
use Tk; use Tk::Balloon; $mw = MainWindow->new(-title => "Simple Balloon example"); $button = $mw->Button(-text => "Exit", -command => sub { exit })->pack; $msgarea = $mw->Label(-borderwidth => 2, -relief => 'groove') ->pack(-side => 'bottom', fill => 'x'); $balloon = $mw->Balloon(-statusbar => $msgarea); $balloon->attach($button, -balloonmsg => "Exit the App", -statusmsg => "Press the Button to exit the application"); $balloon->attach($msgarea, -msg => 'Displays the help text for a widget'); MainLoop;
Figure 23-12 illustrates this example.
Figure 23-12. Using a Balloon as both help text and a status message
Using a status bar is optional. We’ve just included it here to show you how easy it is. Here are the options you can use when creating your Balloon widget:[1]
-
-state => 'balloon' | 'status' | '
both
' | 'none'
Determines if the Balloon widget will be displaying only balloons, only status messages, both (the default), or nothing.
-
-statusbar
=>widget
Tells the Balloon what widget to use for displaying status messages. The widget specified must have a
-text
or-textvariable
option.-
-balloonposition ...
Get Mastering Perl/Tk 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.