The OP’s requirements can be met by making two smallish changes:
my $ent = $mw->Entry(-textvariable => \$value, -validate => 'key', -validatecommand => sub { $_[0] =~ /^(?:|-|\d+|- +\d+)$/ }, # <== new regex -invalidcommand => \&lam_num_error)->pack(); ... sub print { print $value unless $value eq '-'; }
The strategy here is to pass as valid not only the final data entry, but also all intermediate states reached during its construction (including, especially, the empty string, which is the starting state. This allows Reset to work without error). The print sub then applies a final validation, to exclude partially-constructed data.
Incidentally, why does this print sub work? I have verified that it does work as required, but why doesn’t it simply call itself recursively??
Athanasius <°(((>< contra mundum
In reply to Re: Entry Widget - validatecommand
by Athanasius
in thread Entry Widget - validatecommand
by shortyfw06
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |