merrymonk has asked for the wisdom of the Perl Monks concerning the following question:

I want to add balloons (tooltips) and status messages to:
1. Widgets in tabbed frames;
2. Widgets in ‘secondary’ top level widgets.
The Perl code below attempts to do both. It works fine for widgets in tabbed frames.
It does not work for widgets in secondary top level widgets.
I get the result of trying to attach the balloon. For successful attachments this seems to be set to 1.
For the balloons in the other top level widget it is set to 7.
Does anyone know how to get a balloon successfully attached to a secondary top level widget so that it can be seen?
The output of the print statements is
attach result <1> for balloon <Tab 1_Balloon>
attach result <1> for balloon <Tab 2_Balloon>
attach result <1> for balloon <Tab 3_Balloon>
balloon <Tk::Balloon=HASH(0x1b5b768)>
attach result <7> for toplevel Entry balloon
use strict "vars"; use Tk; use Tk::TabFrame; my ($a_tbfr, $tab_mw, $frame_wg); my ($lb_str, $en_str, %tabwg, $tabwg_item, $current_product, $gen_str, + $j, $j_str, %wg, $wg_item, $att_res); my ($msgarea, $balloon_msg, $status_msg, $bl_str); my ($button_sc, $toplevel_entry_wg, $toplevel_wg, $balloon); $current_product = 'unset'; $tab_mw = MainWindow->new; $tab_mw->Label(-text => 'Tabbed Frame to Check Tooltips')->grid(-row = +> 0); # create the tabbed frame $a_tbfr = $tab_mw->TabFrame ( -font =>'-adobe-times-medium-r-bold--14', -tabcurve =>4, -padx => 10, -pady => 10, -width => 400 ); # create the message area for tooltips $msgarea = $tab_mw->Label(-borderwidth => 2, -relief => 'groove') ->grid(-row => 3); # create the tabbed frames each with a label and entry box $a_tbfr->grid ('-row' => 1); for($j = 1; $j <= 3; $j ++) { $j_str = "Tab " . $j; $tabwg{$j_str} = $a_tbfr->Frame ( -caption => $j_str, ); $lb_str = "Tab " . $j . '_Label'; $wg{$lb_str} = $tabwg{$j_str}->Label(-text => "Text in Label in $j +_str", -width => 50)->grid(-row => 2, -column=>0); $en_str = "Tab " . $j . '_Entry'; $wg{$en_str} = $tabwg{$j_str}->Entry (-text => $en_str, -width => 20)->grid(-row => 3, -column=>0); $bl_str = "Tab " . $j . '_Balloon'; $wg{$bl_str} = $tabwg{$j_str}->Balloon(-statusbar => $msgarea); $balloon_msg = "Tab " . $j . " balloon / tooltips message"; $status_msg = "Tab " . $j . " status message"; $att_res = $wg{$bl_str}->attach($wg{$en_str}, -balloonmsg => $ball +oon_msg, -statusmsg => $status_msg); print "attach result <$att_res> for balloon <$bl_str>\n"; } # create a TopLevel widget $toplevel_wg = $tab_mw->Toplevel(); # create an entry box and two labels for this toplevel widget $toplevel_wg->Label(-text => "Text above entry box")->grid(-row => 0); $toplevel_entry_wg = $toplevel_wg->Entry(-width => 20)->grid(-row => 1 +, -column=>0); $toplevel_wg->Label(-text => "Text below entry box")->grid(-row => 2); $balloon = $toplevel_entry_wg->Balloon(-statusbar => $msgarea); print "balloon <$balloon>\n"; $att_res = $balloon->attach($balloon, -balloonmsg => "toplevel entry b +ox balloon/tooltip", -statusmsg => "toplevel entry box sta +tus"); print "attach result <$att_res> for toplevel Entry balloon\n"; MainLoop;

Replies are listed 'Best First'.
Re: How to get balloons (tooltips) on toplevel widget
by biohisham (Priest) on Feb 16, 2010 at 14:13 UTC
    You may need Tk::Balloon as follows.
    use strict; use Tk::Balloon; my $b = $toplevel_wg->Balloon(-statusbar=>$toplevel_wg); $b->attach($toplevel_wg, -balloonmsg => "I am on the smaller window", -statusmsg => "Status bar message");


    Excellence is an Endeavor of Persistence. Chance Favors a Prepared Mind.
Re: How to get balloons (tooltips) on toplevel widget
by keszler (Priest) on Feb 16, 2010 at 14:14 UTC
    $att_res = $balloon->attach($balloon, -balloonmsg => "toplevel entry b +ox balloon/tooltip", ^^^^^^^^ -statusmsg => "toplevel entry b +ox status");
    You appear to be attaching the balloon to itself instead of $toplevel_entry_wg.

    Also, it is not necessary to create multiple balloons unless the attributes (other than -(balloon|status)msg) differ. One balloon widget can be attached to many other widgets, each having a different -(balloon|status)msg.

      I have used the suggestions and corrections and all now works as I wanted it to.
      Therefore many thanks for pointing me in the right direction.
      Below is the Perl for this which now includes a button which brings up the secondary window so that the ‘balloon’ can be tested.
      use strict "vars"; use Tk; use Tk; use Tk::TabFrame; use Tk::Balloon; my ($a_tbfr, $tab_mw, $b_tbfr, $frame_wg); my ($lb_str, $en_str, %tabwg, $tabwg_item, $current_product, $gen_str, + $j, $j_str, %wg, $wg_item, $att_res); my ($msgarea, $balloon_msg, $status_msg, $bl_str); my ($button_sc, $toplevel_entry_wg, $toplevel_wg, $balloon); $current_product = 'unset'; $tab_mw = MainWindow->new; $tab_mw->Label(-text => 'Tabbed Frame to Check Tooltips')->grid(-row = +> 0); # create the tabbed frame $a_tbfr = $tab_mw->TabFrame ( -font =>'-adobe-times-medium-r-bold--14', -tabcurve =>4, -padx => 10, -pady => 10, -width => 400 ); # add button that gives additional screen with button $button_sc = $tab_mw->Button( -text => 'See top level widget', -command => sub { $toplevel_wg->deiconify(); $toplevel_wg->raise(); }) ->grid(-row => 2); # create the message area for tooltips $msgarea = $tab_mw->Label(-borderwidth => 2, -relief => 'groove') ->grid(-row => 3); # create a ballon for this message area etc $balloon = $tab_mw->Balloon(-statusbar => $msgarea); # create the tabbed frames each with a label and entry box $a_tbfr->grid ('-row' => 1); for($j = 1; $j <= 3; $j ++) { $j_str = "Tab " . $j; $tabwg{$j_str} = $a_tbfr->Frame ( -caption => $j_str, ); $lb_str = "Tab " . $j . '_Label'; $wg{$lb_str} = $tabwg{$j_str}->Label(-text => "Text in Label in $j +_str", -width => 50)->grid(-row => 2, -column=>0); $en_str = "Tab " . $j . '_Entry'; $wg{$en_str} = $tabwg{$j_str}->Entry (-text => $en_str, -width => 20)->grid(-row => 3, -column=>0); $balloon_msg = "Tab " . $j . " balloon / tooltips message"; $status_msg = "Tab " . $j . " status message"; $att_res = $balloon->attach($wg{$en_str}, -balloonmsg => $balloon_ +msg, -statusmsg => $status_msg); print "attach result <$att_res> for widget <$en_str>\n"; } # create a TopLevel widget $toplevel_wg = $tab_mw->Toplevel(); # create an entry box for this toplevel widget $toplevel_wg->Label(-text => "Text above entry box")->grid(-row => 0); $toplevel_entry_wg = $toplevel_wg->Entry(-width => 20)->grid(-row => 1 +, -column=>0); $toplevel_wg->Label(-text => "Text below entry box")->grid(-row => 2); # withdraw the second toplevel widget $toplevel_wg->withdraw(); $att_res = $balloon->attach($toplevel_entry_wg, -balloonmsg => "toplev +el entry box balloon/tooltip", -statusmsg => "toplevel entry box sta +tus"); print "attach result <$att_res> forwidget <top_level_entry>\n"; MainLoop;