http://www.perlmonks.org?node_id=951101

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

Anyone have an example of attaching a Tk balloon to a Tk menu list when the list is configured per the "unclunky" (slick,sophisticated, new-fashioned) way of Mastering Perl/Tk (1st Ed) on page 261 like so...?

map { $menubar->cascade( -label => '~' . $_->[0], -menuitems => $_->[1 +]) } [ 'Choices', char_string ]; sub char_string { [ ['command', 'foo', -command => sub { $char_string = "this"} ], ['command', 'bar', -command => sub { $char_string = "that"} ], ] }

That works fine without balloons. But for adding balloons to menus, the CPAN docs show an example similar to...

$b->attach( $menu, -state => 'balloon', -msg => [ 'Do this...', 'Do that...', ], );

...which requires a scalar "$menu". With the map construction I no not how to get such a scalar. I could get scalars for "$menu" as I do the "clunky" way from page 259. But I hate to go back to clunkyness.

Anybody got an example? My Perl is very rusty from not using it much these past 5 years. So please translate answers into noobish if possible. Thanks.

Replies are listed 'Best First'.
Re: Tk::Balloon and unclunky menus.
by Anonymous Monk on Feb 01, 2012 at 03:15 UTC
    map { my $junk = $men.... $globalBaloonWidget->attach( $junk, -balloonmsg => $_->[-1] ); ...

      That seems not to quite work. After several tries I reduced my usage to a simpler experimental case, thus...

      my $whatever; use subs qw/bar/; map { my $menu = $menubar->cascade( -label => '~' . $_->[0], -menuitems => $_->[1]); $balloon->attach( $menu, -state => 'balloon', -msg => 'foo'); } [ 'Foo', bar ]; sub bar { [ ['command', 'This', -command => sub { $whatever = 'Does this.'}], ['command', 'That', -command => sub { $whatever = 'Does that'}], ] }

      But I get the error...

      Can't locate object method "OnDestroy" via package "Tk::Menu::Cascade" at C:/Strawbery/perl/site/lib/Tk/Balloon.pm line 139.

      The difference is that I'm not even mapping the argument for -msg => as $_->[2] or $_->[-1] but just giving unmapped 'foo'. Any thoughts?

        Alas and alack, I read that we just can't do Balloons for Menus on Windows. Per the post here PerlMonks Friar lamprecht says, "Windows is special in that events over Menu windows are not passed to Tk so Balloon will not work here."