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

I have a Tk::Tree widget that I'd like to attach some balloon help messages. Based on the notes I found on canvas balloon help and browseentry balloon help I wrote this code:
use strict; use warnings; use Tk; use Tk::Tree; use Tk::Balloon; my $mw = MainWindow->new(); my $h = $mw->Scrolled('Tree', -scrollbars=>'ose', -selectmode=>'extend +ed')->pack(-side=>'top', -fill=>'both', -expand=>1); my %help; for my $top (1..3) { $h->add($top, -text=>$top); for (1..3) { $h->add("$top.$_", -text=>"$top.$_"); $help{"top.$_"} = "help_$top.$_"; } } my $b = $mw->Balloon(-initwait=>0); $b->attach($h->Subwidget('scrolled'), -balloonposition=>'mouse', -msg= +>\%help); MainLoop();
However, This gives me a flurry of "malformed UTF-8 error messages and garbage balloon help. I did some searching on google and found this post, which implies that perhaps this functionality does not exist yet. Is that the case or am I doing something wrong?

Replies are listed 'Best First'.
Re: Using Tk::Balloon with Tk::Tree
by zentara (Cardinal) on Dec 22, 2006 at 18:24 UTC
    Here is a way to use the hash for message storage. It needs some improvement, but it shows the basics.
    #!/usr/bin/perl use strict; use warnings; use Tk; use Tk::Tree; use Tk::Balloon; my $mw = MainWindow->new(); my $mess = ''; my $h = $mw->Scrolled( 'Tree', -scrollbars => 'ose', -selectmode => 'extended' )->pack( -side => 'top', -fill => 'both', -expand => 1 ); my %help; for my $top ( 1 .. 3 ) { $h->add( $top, -text => $top ); for ( 1 .. 3 ) { $h->add( "$top.$_", -text => "$top.$_" ); $help{ $top . '.' . $_ } = "help_$top.$_"; print "$top$_\n"; } } my $b = $mw->Balloon( -initwait => 0 ); $b->attach( $h->Subwidget( 'scrolled' ), -balloonposition => 'mouse', #-msg=>\%help); -msg => \$mess, -motioncommand => sub { my ( $lb, $x, $y ) = @_; $x -= $h->Subwidget( 'scrolled' )->rootx; $y -= $h->Subwidget( 'scrolled' )->rooty; #print "$x $y\n"; my $index = $h->Subwidget( 'scrolled' )->nearest( $y ); print "$index\n"; if ( $index ) { $mess = $help{ $index }; # put the balloon msg here 0; # show balloon } } ); MainLoop();

    I'm not really a human, but I play one on earth. Cogito ergo sum a bum
      Awesome! That's exactly what I was looking for. Thanks a (CPAN) bundle :-)
Re: Using Tk::Balloon with Tk::Tree
by ldln (Pilgrim) on Dec 22, 2006 at 18:09 UTC
    Try attaching scalar or scalaref instead of hashref to ballonmsg:
    use strict; use warnings; use Tk; use Tk::Tree; use Tk::Balloon; my $mw = MainWindow->new(); my $h = $mw->Scrolled('Tree', -scrollbars=>'ose', -selectmode=>'extend +ed')->pack(-side=>'top', -fill=>'both', -expand=>1); my %help; for my $top (1..3) { $h->add($top, -text=>$top); for (1..3) { $h->add("$top.$_", -text=>"$top.$_"); $help{"top.$_"} = "help_$top.$_"; } } my $b = $mw->Balloon(-initwait=>0); #$b->attach($h->Subwidget('scrolled'), -balloonposition=>'mouse', -bal +loonmsg=>\%help); $b->attach($h->Subwidget('scrolled'), -balloonposition=>'mouse', -ball +oonmsg=>"OK"); MainLoop();