in reply to Tk validateCommand Help
You can also use the caller method to get which widget called the sub like in the example below. You can use the caller in conjunction with hashes, to do some complex switching. You could put each entry's specifications into a hoh like-validatecommand => [\&Validate_Number, $entry_limit]
Then in your validate callback, just pass the entry number likemy %entry =( 1=>{ 'object' =>undef, 'upperlim => 42, 'lowerlim =>0 }, 2=>{ 'object' =>undef, 'upperlim => 99, 'lowerlim =>-23 }, );
-validatecommand => [\&Validate_Number, 1]
Here is an example using button to demonstrate the caller function.
#!/usr/bin/perl use strict; use Tk; my $mw = MainWindow->new; for(0..4){ $mw->Button(-text => "Hello World$_", -command=>[\&change])->pack; } MainLoop; sub change { print "sub-input->@_\n"; my $caller = $Tk::widget; print "$caller "; print $caller->{'_TkValue_'},' '; my $text = $caller->cget('-text'); print "$text\n"; $caller->configure(-text=>"Hello Stranger"); }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Tk validateCommand Help
by NateTut (Deacon) on Jun 07, 2005 at 13:02 UTC |