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.
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:[68]
[68] Not all the options are detailed here, only those used 99% of the time. See the documentation included with the widget for a complete listing.
Once the Balloon is created, you can both attach and detach widgets. Here's the attach method:
$balloon->attach($widget, option => value, ... );
This method takes a widget and a list of the following option/value pairs:
You can override any of the -initwait, -state, -statusbar, or -balloonposition options with each individual call to attach.
The balloon demo included with the widget demo application is quite good; it shows attaching a Balloon to text widgets, canvas items, and various other widgets.
Copyright © 2002 O'Reilly & Associates. All rights reserved.