Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Re: If the text widget does not have the focus, the selection tag is not visible

by Anonymous Monk
on Nov 14, 2009 at 20:13 UTC ( [id://807174]=note: print w/replies, xml ) Need Help??


in reply to If the text widget does not have the focus, the selection tag is not visible

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;
  • Comment on Re: If the text widget does not have the focus, the selection tag is not visible
  • Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://807174]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others studying the Monastery: (6)
As of 2024-04-23 11:53 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found