Use strict warnings and diagnostics or die :)
#!/usr/bin/perl --
use strict;
use warnings;
use Tk;
my $mw = MainWindow->new;
my $filename;
# Create necessary widgets
my $f = $mw->Frame->pack( -side => 'top', -fill => 'x' );
$f->Entry( -textvariable => \$filename )->pack(
-side => 'left',
-anchor => 'w',
-fill => 'x',
-expand => 1
);
$f->Button( -text => "Exit", -command => sub { exit; } )
->pack( -side => 'right' );
my $t = $mw->Scrolled("Text")->pack(
-side => 'bottom',
-fill => 'both',
-expand => 1,
);
$t->insert( end => join "\n", 1 .. 10 );
$t->focus;
$t->bind(
'<<Selection>>',
sub {
#~ warn @_;
my ($t) = @_;
$t->tagDelete('ssel');
if ( my (@range) = $t->tagRanges('sel') ) {
$t->tagAdd( ssel => @range );
for my $opt (qw' foreground background ') {
$t->tagConfigure( ssel => "-$opt" => $t->cget("select$opt") );
}
} ## end if ( my (@range) = $t->tagRanges...)
return;
}
);
$t->bind(
'<FocusOut>',
sub {
my ($t) = @_;
#~ print $t->getSelected;
#~ use Data::Dumper; print Dumper([ $t->tagConfigure('ssel') ]);
#~ use Data::Dumper; print Dumper([ $t->tagNames ]);
#~ use Data::Dumper; print Dumper([ $t->tagRanges('sel') ]);
return;
}
);
MainLoop;