O'Reilly logo

Mastering Perl/Tk by Nancy Walsh, Stephen Lidie

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

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.

Using a Balloon as both help text and a status message

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

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