Tk::FilterEntry - An entry with filter
use Tk::FilterEntry; $entry = $parent->FilterEntry(?options?); $entry->pack;
This widget is derived from Tk::Entry and it implements an other way of validation. The input is validate by a callback or more simply by a filter, when the entry leaves the focus. And if is invalid, the foreground color is changed.
So, this widget deals well with textVariable.
The color of the input text when it is valid.
The default value is 'black'.
The color of the input text when it is not valid.
The default value is 'red'.
This filter specifies the valid range of the input.
The filter is used if validatecommand is not defined.
The filter is a Perl regular expression.
The default value is '.*' (every is valid).
If the boolean value specified is true, the leading and trailing whitespace are skipped before apply the filter.
The default value is 1.
If the boolean value specified is true, the two anchors '^' and '$' are added to the filter.
This Entry callback is called if defined. The boolean value returned defines if the input is valid.
The validateCommand and invalidCommand are called with first argument: the reference of the entry (It is a major different with Tk::Entry) and following by parameters of the closure.
The default value is <undef>.
This Entry callback is called if the return of validateCommand is false or if the input doesn't match with the pattern.
This command is used to force an evaluation of the validateCommand or of the filter.
It returns boolean.
my $hour; # with format HH:mm my $e_hour = $mw->FilterEntry( -filter => '[0-2]?\d:[0-5]?\d', -invalidcommand => sub { print "invalid ",shift->get(),"\n" }, -textvariable => \$hour, -width => 15, );
or
my $hour; # with format HH:mm my $e_hour = $mw->FilterEntry( -validatecommand => sub { shift->get() =~ /^\s*[0-2]?\d:[0-5]?\d\s*$/ }, -invalidcommand => sub { print "invalid ",shift->get(),"\n" }, -textvariable => \$hour, -width => 15, );
my $hour; # with format HH:mm my $e_hour = $mw->FilterEntry( -validatecommand => [ sub { $_[0]->get() =~ /$_[1]/ }, '^\s*[0-2]?\d:[0-5]?\d\s*$' ], -invalidcommand => sub { print "invalid ",shift->get(),"\n" }, -textvariable => \$hour, -width => 15, );
Tk::Entry
(c) 2003 Francois PERRAD, France. All rights reserved.
This library is distributed under the terms of the Artistic Licence.
Francois PERRAD, francois.perrad@gadz.org
To install Tk::FilterEntry, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Tk::FilterEntry
CPAN shell
perl -MCPAN -e shell install Tk::FilterEntry
For more information on module installation, please visit the detailed CPAN module installation guide.