Tk has no standard for the first element being passed to a sub.
Only the bind method will pass itself as a widget reference as $_[0] by default. So you have to work out your own system. You have a couple of options. You can pass it like davidrw showed you, or you can use a different syntax like
-validatecommand => [\&Validate_Number, $entry_limit]
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
my %entry =(
1=>{ 'object' =>undef,
'upperlim => 42,
'lowerlim =>0
},
2=>{ 'object' =>undef,
'upperlim => 99,
'lowerlim =>-23
},
);
Then in your validate callback, just pass the entry number like
-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");
}
I'm not really a human, but I play one on earth.
flash japh
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.