| 1 |
#!/usr/local/bin/perl -w |
| 2 |
use strict; |
| 3 |
use Tk; |
| 4 |
|
| 5 |
my $mw = MainWindow->new; |
| 6 |
|
| 7 |
my $text = '0123456789'; |
| 8 |
|
| 9 |
my $e = $mw->Entry(-validate => 'all', -textvariable => \$text, |
| 10 |
-vcmd => \&validate, |
| 11 |
-invcmd => sub { $mw->bell })->pack; |
| 12 |
my $l = $mw->Label(-textvariable => \$text)->pack; |
| 13 |
|
| 14 |
$mw->Button(-text => 'Set', -command => sub { $text = '0123456789' })->pack; |
| 15 |
$mw->Button(-text => 'MisSet', -command => sub { $text = 'A012345678' })->pack; |
| 16 |
$mw->Button(-text => 'Quit', -command => [destroy => $mw])->pack; |
| 17 |
MainLoop; |
| 18 |
|
| 19 |
sub validate |
| 20 |
{ |
| 21 |
my @args = @_; |
| 22 |
foreach (@args) |
| 23 |
{ |
| 24 |
$_ = defined ($_) ? "'$_'" : 'undef'; |
| 25 |
} |
| 26 |
print 'validate ',join(',',@args),"\n"; |
| 27 |
return $_[0] =~ /^\d*$/; |
| 28 |
} |
| 29 |
|
| 30 |
|