use strict; use warnings; use Tk; my $mw = new MainWindow; my $tw = $mw->Text()->pack(-expand => 1, -fill => 'both'); foreach my $item (qw( item1 item2 item3 )) { my $tagname = $item; $tw->tagBind($tagname, "", sub { clicked_item($item) }); $tw->insert('end', $item, $tagname); $tw->insert('end', "\n"); } MainLoop; sub clicked_item { my ($item) = @_; print "You clicked on item $item!\n"; } #### use strict; use warnings; use Tk; my $mw = new MainWindow; my $tw = $mw->Text()->pack(-expand => 1, -fill => 'both'); my $p_enter = sub { $_[0]->configure(-cursor => 'hand2') }; my $p_leave = sub { $_[0]->configure(-cursor => 'xterm') }; foreach my $item (qw( item1 item2 item3 )) { my $tagname = $item; $tw->tagBind($tagname, "", sub { clicked_item($item) }); $tw->tagBind($tagname, "", $p_enter); $tw->tagBind($tagname, "", $p_leave); $tw->insert('end', $item, $tagname); $tw->insert('end', "\n"); } MainLoop; sub clicked_item { my ($item) = @_; print "You clicked on item $item!\n"; }