I think you have to add your event (button check for example, lost focus...), to check the text, I didn't find this binding on Text widget. Maybe with "Grab" to get all input.
The following code will tell you if the text has been found (in console) and will scroll to the text searched.
You could also highlight this text (with Tags) but I don't have enough time and it's out of scope of my application lol (I don't want to create an editor XD).
I hope it will help you...
Peace
use strict; use warnings; use Tk; use feature qw(say); my $lblText = "Search:"; my $searchText = ""; my $txtContent = "Perl/Tk is probably the most widely known GUI for Pe +rl. It is a great interface used by thousands of people. I am writing + this to teach those with no previous knowledge of any programming la +nguage or GUI interface. You should know some Perl (you don't need to + be an expert, but you need to know some basic/intermediate Perl) bef +ore you read this also. Perl/Tk is a module, so it should be fairly e +asy to get. If you don't know how to install modules"; $txtContent .= reverse $txtContent; $txtContent =~ s/ /\n/g; # ponctuation not allowed my $mw = new MainWindow(-title => "Search demo"); my $lbl = $mw -> Label(-text => $lblText)->pack(); my $search = $mw -> Entry(-textvariable => \$searchText, -validate => "key", -validatecommand => sub {$_[1] !~ /[;,.:!?]/}, + -invalidcommand => sub {$mw->bell})->pack(); my $textarea = $mw -> Frame() ->pack(); my $txt = $textarea -> Text(-width => 40, -height => 10)->pack(); $txt->insert('end', $txtContent); my $btnCheck = $mw ->Button(-text => "Check", -command => sub {&check_text();})->pack(); + MainLoop; sub check_text() { return if (length $searchText == 0); say "Searching: ", $searchText; my $result = $txt->search(-nocase => $searchText, 'end'); if (defined($result)) { say "Found at pos: $result"; $txt->see($result); } else { say "Not found!"; } } __END__

In reply to Re^3: How to validate text in Text widge by hotchiwawa
in thread How to validate text in Text widge by Kafka

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.