How do pass arguments to subroutines in Perl/Tk?
I have designed one sign-up form,in this form after getting all necessary values I will click submit button.
And while clicking that submit button I want to call one function and I want to pass the arguments to that function.
I have written code for this purpose,but the function is called first before 开发者_JAVA百科getting the details.(i.e)after getting the details in sign-up form I need to pass these values to one function and I need to validate those values.
But what happened was,before getting the details the function get called.
Carlos's suggestion is one way. Another is to put a command callback on the button that reads the values out of the form and calls your function, perhaps like this.
$button->configure(-command => sub { yourFunc($var1, $var2); });
I'm assuming you've bound the fields of the form to the variables $var1
and $var2
here; modify to fit your own situation of course.
You have a number of options when specifying a code ref and arguments to a bind to a widget:
$w->configure( -command => [ \&subname, @args ... ] );
$w->configure( -command => [ sub { ... }, @args ... ] );
$w->configure( -command => [ 'methodname', $invocant, @args ... ] );
$w->configure( -command => [ $invocant, 'methodname', @args ... ] );
See the Tk::callbacks POD for more info.
Sounds like a vwait problem. Check in the Perl/Tk documentation for:
$widget->waitVariable(varRef)
In this way you are sure your code is only executed when the wait variable is modified (that's when you click the "submit" button)
Hope it helps.
精彩评论