Balloons

In the last chapter we gave an example of the use of bind to display a help message when the cursor enters an area of the window associated with some widget. The balloon widget can also be used to do this, as well as displaying a small window beside the widget with another message. The basic syntax of this widget is
my $balloon = $mw->Balloon( [option => value);
A basic option is -statusbar => $widget, where $widget is the name of the widget used to display the statusbar. The balloon is attached to a given widget by the attach method:
$balloon->attach($widget( [option => value);
Options to the attach method are An example of the use of the balloon widget appears below.
#!perl
# file balloon.pl
use Tk;
use Tk::Balloon;
use strict;
use warnings;
my $mw = MainWindow->new;
$mw->title('Balloon help');
my $status = $mw->Label(-width => 25,
                        -height => 10,
                        -relief => 'sunken',
                       );
my $balloon = $mw->Balloon(-statusbar => $status);
my $exit = $mw->Button(-text => 'Exit',
                      -command => [$mw => 'destroy']);
$balloon->attach($exit,
                 -balloonmsg => 'Press here to exit',
                 -statusmsg => "The mouse is over\n the exit button",
                );
$exit->pack;
$status->pack;
MainLoop;
In this case the $status widget is a Label widget. The balloon widget is attached to the $exit button, and when the cursor pauses over this button, a balloon pops up with the indicated message, with a different message appearing in the status window. A screenshot of this example appears below.

Figure 3.24: Example of a help balloon
Image balloon

Randy Kobes 2003-11-17