#!/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', '', sub { my $message= $text->get('1.10', '1.13');# this should become dynamic $balloon->attach($text , -balloonmsg => $message, -initwait => 10, -balloonposition => 'mouse'); }); $text->tagBind('red_text', '', sub { $balloon->detach($text) }); $mw->MainLoop();