You aren't supplying enough information for anyone to really help you figure out your problem. The best I can come up with is "You're doing it wrong."
Try this code snippet to see if it gives you any pointers.
use strict;
use warnings;
use Tk;
my %w;
$w{mw} = MainWindow->new;
$w{topfr} = $w{mw}->Frame()->pack( -expand => 1, -fill => 'x' );
$w{textfr} = $w{mw}->Frame()->pack( -expand => 1, -fill => 'both' );
$w{topfr}->Button(
-text => 'Previous',
-command => sub { nextText('-backwards') }
)->pack( -side => 'left' );
$w{searchstring} =
$w{topfr}->Entry( -text => 'text', )->pack( -side => 'left' );
$w{topfr}->Button(
-text => 'Next',
-command => sub { nextText('-forwards') }
)->pack( -side => 'left' );
$w{textWindow} =
$w{textfr}->Scrolled( 'Text', -scrollbars => 'ose' )
->pack( -expand => 1, -fill => 'both' );
$w{textWindow}->insert(
'end',
q|I have a Scrolled Text widget in my application. I am trying to
implement an incremental search of a string on this text widget.
I have come up with the following logic , but it only highlights
the first occurence and not the remaining ocuurences. Please help
me to make it incremental for the entire text widget.
Following is my code |
);
$w{textWindow}->focus;
MainLoop;
sub nextText {
my $direction = shift;
my $string = $w{searchstring}->get;
$w{textWindow}->FindNext( $direction, '-exact', '-nocase', $string
+ );
}