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();

In reply to Re^2: Attaching a balloon message to text on the Text widget by Anonymous Monk
in thread Attaching a balloon message to text on the Text widget by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.