If I want to dynamically assign the value of -balloonmsg, for example the content of the tagged text? In the following I have 2 words tagged, the balloon should diasplay as message the respectiv text which is tagged. I simulate this reading the content with "get", but I use fix indexes and of course it is not okay. Any idea how to get those indexes dynamically?
#!/usr/bin/perl
use strict;
use warnings;
use Tk;
use Tk::Text;
use Tk::Balloon;
my $mw = tkinit();
my $text = $mw->Text->pack;
$text->insert('end', "This is a red text\n");
$text->tagAdd('red_text', '1.10', '1.13');
$text->insert('end', "This is another xxx text\n");
$text->tagAdd('red_text', '2.16', '2.19');
$text->tagConfigure('red_text', -foreground => 'red');
my %messages = (1=>"hello", 2=>"good");
my $balloon = $text->Balloon();
$text->tagBind('red_text', '<Enter>', sub {
my $message= $text->get('1.10', '1.13');# this should become dynam
+ic
$balloon->attach($text , -balloonmsg => $message,
-initwait => 10,
-balloonposition => 'mouse');
});
$text->tagBind('red_text', '<Leave>', sub { $balloon->detach($text) })
+;
$mw->MainLoop();
| [reply] [d/l] |
If you want each tag to display a different balloon message, you need different tags:
#!/usr/bin/perl
use strict;
use warnings;
use Tk;
use Tk::Balloon;
my $tag_counter = 0;
sub tag_and_balloonify {
my ($text, $tag, $balloon, $x, $y) = @_;
$tag .= ++$tag_counter;
my %messages = (1 => 'hello', 2 => 'good');
my $message = $messages{$tag_counter};
$text->tagAdd($tag, $x, $y);
$text->tagBind($tag, '<Enter>', sub {
$balloon->attach($text,
-balloonmsg => $message,
-initwait => 10,
-balloonposition => 'mouse');
});
$text->tagBind($tag, '<Leave>', sub { $balloon->detach($text) });
$text->tagConfigure($tag, -foreground => 'red');
}
my $mw = tkinit();
my $text = $mw->Text->pack;
my $balloon = $text->Balloon();
$text->insert('end', "This is a red text\n");
tag_and_balloonify($text, 'red_text', $balloon, '1.10', '1.13');
$text->insert('end', "This is another xxx text\n");
tag_and_balloonify($text, 'red_text', $balloon, '2.16', '2.19');
$mw->MainLoop();
($q=q:Sq=~/;[c](.)(.)/;chr(-||-|5+lengthSq)`"S|oS2"`map{chr |+ord
}map{substrSq`S_+|`|}3E|-|`7**2-3:)=~y+S|`+$1,++print+eval$q,q,a,
| [reply] [d/l] [select] |
| [reply] |