如何在 Perl/Tk 中将参数传递给子例程?

发布于 2024-08-27 10:12:19 字数 197 浏览 3 评论 0原文

我设计了一份注册表单,在获得所有必要的值后,我将在该表单中单击“提交”按钮。

单击提交按钮时,我想调用一个函数,并将参数传递给该函数。

我已经为此目的编写了代码,但在获取详细信息之前首先调用该函数。(即)在注册表单中获取详细信息后,我需要将这些值传递给一个函数,并且需要验证这些值。

但发生的事情是,在获取详细信息之前,函数被调用。

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 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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

才能让你更想念 2024-09-03 10:12:19

卡洛斯的建议是一种方法。另一种方法是在按钮上放置一个命令回调,该按钮从表单中读取值并调用您的函数,也许像这样。

$button->configure(-command => sub { yourFunc($var1, $var2); });

我假设您已将表单的字段绑定到变量 $var1$var2 ;当然要根据自己的情况进行修改。

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.

郁金香雨 2024-09-03 10:12:19

在指定绑定到小部件的代码引用和参数时,您有许多选项:

$w->configure( -command => [ \&subname,   @args ... ]             );
$w->configure( -command => [ sub { ... }, @args ... ]             );
$w->configure( -command => [ 'methodname', $invocant, @args ... ] );
$w->configure( -command => [ $invocant, 'methodname', @args ... ] );

请参阅 Tk::callbacks POD 了解更多信息。

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.

两相知 2024-09-03 10:12:19

听起来像是 vwait 问题。检查 Perl/Tk 文档:

$widget->waitVariable(varRef)

通过这种方式,您可以确定您的代码仅在修改等待变量时执行(即单击“提交”按钮时)

希望它有所帮助。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文