Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling

Re: Perl tk FindNext in a text widget

by thundergnat (Deacon)
on May 29, 2013 at 14:28 UTC ( #1035856=note: print w/replies, xml ) Need Help??

in reply to Perl tk FindNext in a text widget

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 + ); }

Replies are listed 'Best First'.
Re^2: Perl tk FindNext in a text widget
by ghosh123 (Monk) on May 30, 2013 at 06:38 UTC

    Hi thundergnat
    Despite insufficient information, you have understood my requirement excellently and exactly this is what I was looking for.
    The only thing is "Previous" button working fine, but the "Next" button is only highlighting the first occurence of the search string and not able to go forward.
    I checked with caller(0) and other print statements. While pressing "Next", it is getting called properly with proper argument i.e "-forwards" but still the problem persists.

    Thanks anyways.

        Sorry to disagree, 'next' button does not work incrementally unlike 'prev' button. Clicking the 'next' button does not go on highlighting all the occurence of the search text. It only highlights the first occurence and then stops working.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1035856]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (3)
As of 2018-05-26 07:14 GMT
Find Nodes?
    Voting Booth?