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

I want to have a balloon (tooltip) on an optionmenu that is different for each Item on the drop down menu.
I found an example which allegedly did this. However, it gave an error shown below.
The Perl below is this example which as it is now gives the same tooltip and message in a label for each menu option.
The code that is supposed to give the variable message is hashed out.
To see the error simply remove the #on the first -balloonmsg line and add a # to the second -balloonmsg line.
Can any wise Monk explain how to get a different message for each option on the pull-down menu?
#!/usr/local/bin/perl use strict; use warnings; use Tk; use Tk::Balloon; my ($att_res); my $mw = MainWindow->new(); $mw->title('Simple example'); my $status = $mw->Label( -width => 20, -relief => 'groove', )->pack(); my $balloon = $mw->Balloon(-statusbar => $status, -initwait => 1); my $menu = $mw->Optionmenu( -textvariable => \my $res, -options => [qw(A B C D)], )->pack(); $att_res = 1234; $att_res = $balloon->attach( $menu, # pass the Tk::Menu instance # the next line gave many errors of the form #Malformed UTF-8 character (unexpected non-continuation byte 0xe5, imm +ediately after start byte 0xf0) # in subroutine entry at ......./lib/Tk.pm line 469. # -balloonmsg => [qw(a b c d)], -balloonmsg => 'foo', -statusmsg => 'foo', # this works, but you get the same msg for all menu entries, of co +urse ); print "att_res <$att_res\n"; MainLoop;

Replies are listed 'Best First'.
Re: Perl Tk - Varying balloon message on optionmenu
by beech (Parson) on Mar 17, 2016 at 23:52 UTC

    Can any wise Monk explain how to get a different message for each option on the pull-down menu?

    Try  $balloon->attach( $menu->menu, -balloonmsg => [qw(a b c d)], ); as per Re^6: Balloon and menus options

    It doesn't work on windows, this is a bug

      I tried the suggested line. No more errors but nothing was shown as a balloon. Therefore it looks like a bug!