in reply to GUI with clickable/selectable single-line messages
This example shows just the basics, I print the data to stdout, instead of a balloon or a toplevel extra-info window. Also, I create 100 tags in a simple loop, but in your situation, you will wnat to tagconfigure each tag, for each line, as they come in and are printed.
#!/usr/bin/perl use warnings; use strict; use Tk; my $mw = tkinit; my $t = $mw->Scrolled('Text', -scrollbars => 'osoe' )->pack; for(1..100){ $t->tagConfigure( 'data'.$_, -data => $_ x 20, ); } for(1..100){ $t->insert('end', 'Line'."$_\n", ['datarider','data'.$_ ]); } $t->tagBind( 'datarider', '<Enter>', sub { getdata($t) } ); $t->tagBind( 'datarider', '<Leave>', sub { getdata($t) } ); $t->bind( '<Motion>', sub{ getdata($t) } ); MainLoop; sub getdata { my ( $text_widget ) = @_; my $x = $text_widget->pointerx - $text_widget->rootx; my $y = $text_widget->pointery - $text_widget->rooty; #print "$x $y\n"; my $txt_index = $text_widget->index( '@' . $x . ',' . $y ); #warn $txt_index; my ( $line, $char ) = ( $txt_index =~ /^(.+?)\.(.+?)$/ ); my @tags = $text_widget->tagNames($txt_index); print "@tags\n"; foreach my $tag(@tags){ print $text_widget->tagCget($tag,'data'),"\n"; } }
|
|---|