#!/usr/bin/perl -- use strict; use warnings; use Tk; Main( @ARGV ); exit( 0 ); sub Main { tkgui(0, 'who appears selected ? (with exportselection only)'); tkgui(1, 'who appears selected ? (with exportselection and callbac +ks)'); } sub tkgui { my ( $bind_callbacks , $message ) = @_; my $exportselection = 0; my $mw = MainWindow->new; my $filename = $message; my $f = $mw->Frame->pack( -side => 'top', -fill => 'x' ); my $e = $f->Entry( -textvariable => \$filename, -exportselection => $exportselection, )->pack( -side => 'left', -anchor => 'w', -fill => 'x', -expand => 1, ); my $t = $mw->Scrolled( "Text", -exportselection => $exportselection, )->pack( -side => 'bottom', -fill => 'both', -expand => 1, ); $t->insert( end => join "\n", qw' to hilite highlight selection without w/o focus tagAdd tagname @range tagConfigure foreground and background ', 1 .. 10, ); if( $bind_callbacks ){ $t->bind( '<<Selection>>', \&on_selection ); $t->bind( '<FocusOut>', sub { my ($t) = @_; }, ); } $mw->withdraw; $mw->deiconify; $mw->raise; $mw->focusForce; $mw->update; for( 1 .. 5 ){ $filename = "$message [I HAVE FOCUS]"; $e->selectionRange(0, length($filename) - 8 ); $e->focus ; $e->update; $mw->update; warn 'focusCurrent? ', eval { $mw->focusCurrent } || 'none'; sleep 1; $filename = "$message [I LOST FOCUS]"; $t->selectAll; $t->focus; $t->update; $mw->update; warn 'focusCurrent? ', eval { $mw->focusCurrent } || 'none'; sleep 1; } $mw->withdraw; return $mw; } sub on_selection { 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" +) ); } } return; }

In reply to Re: Perl tk FindNext in a text widget by Anonymous Monk
in thread Perl tk FindNext in a text widget by ghosh123

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.