Le Ven 17 Mai 2013 17:31:39, SREZIC a écrit :
Show quoted text> On 2012-05-09 08:40:26, DJIBEL wrote:
> > Dear,
> >
> > -invalidcommand option not seem to be work.
> > run this script to see.
> >
> > Return 0 have not effect too use -invalidcommand.
> >
> > Best Regards,
> >
> > N.B. Perl 5.14 (ActivePerl) on Windows XP, Debian (perl 5.10).
> >
> > #!/usr/bin/perl
> > use warnings;
> > use strict;
> > use Tk;
> >
> > my $mw = MainWindow->new(-title => "spinbox");
> > my $spinbox1 = $mw->Spinbox(
> > -width => 20,
> > -value => [1 .. 10],
> > -validate => 'all',
> > -vcmd => \&validate,
> > -invalidcommand => \&invalidate,
> > )->pack;
> >
> > sub validate {
> > my ($proposed_value, undef, $current_value) = @_;
> > if ( $proposed_value == 3 ) { return 0; }
> >
> > print "$current_value and $proposed_value\n";
> > return 1;
> > }
> >
> > sub invalidation {
> > my ($proposed_value, undef, $current_value) = @_;
> > print "invalid : $proposed_value\n";
> > $mw->bell;
> > }
> >
> > MainLoop();
>
> I see a problem in your script: -invalidcommand calls invalidate, but
> the sub is actually called invalidation.
>
> Regards,
> Slaven
Dear Slaven,
Test this script :
#!/usr/bin/perl
use warnings;
use strict;
use Tk;
my $mw = MainWindow->new(-title => "spinbox");
my $spinbox1 = $mw->Spinbox(
-width => 20,
-value => [1 .. 10],
-validate => 'all',
-vcmd => \&validate,
-invalidcommand => \&invalidation,
)->pack;
sub validate {
my ($proposed_value, undef, $current_value) = @_;
if ( $proposed_value == 3 ) {
print "Sub : validate -> $proposed_value\n";
$mw->bell;
return 0;
}
print "$current_value and $proposed_value\n";
return 1;
}
sub invalidation {
my ($proposed_value, undef, $current_value) = @_;
print "Sub : invalidation -> $proposed_value and $current_value\n";
$mw->bell;
}
MainLoop();
The invalidation sub is never called.
If you use spinbox from 1 to 10, at 3, the invalidation sub is not called, just validate sub. And after that, from 4 to 10 any sub didn't called.
Best Regards,
Djibel