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
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |