您的位置:首页 >> Web开发 >> CGI技术 >> 正文
CGI技术 RSS
 

Perl/Tk FAQ - 10.16. 如何获取输入框(Entry)中的内容

http://www.rdxx.com 06年08月12日 00:00 我要投稿

关键词: 内容 , 获取 , FAQ , NT , Perl

  原文:

10.16. How do I get the entry in an Entry?

You want to call get on the return value of the widget itself. Here is how it may be used in a simplified version of example 1.1 from the Tk::UserGuide where a Button is set up to call a sub where the call to get lies: #!/usr/bin/perl -w use strict; use Tk; my $main = MainWindow -> new(); my $entry = $main -> Entry(); $entry -> pack; $main->Button(-text => 'Print', -command => sub{do_print($entry)} )->pack; MainLoop; sub do_print { my ($widget) = @_; my $entered = $widget -> get(); print "The string "$entered" was entered.\n"; }



译文:

10.16. 如何获取输入框(Entry)中的内容?



简单的说,就是对此输入框调用“get”方法。下面的例子是从UserGuide中的example1.1简化来的,其中设置了一个按钮——关联了一个调用get方法的子程序:

#!/usr/bin/perl -w

use strict;

use Tk;



my $main = MainWindow -> new();

my $entry = $main -> Entry();

$entry -> pack;

$main->Button(-text => 'Print',

-command => sub{do_print($entry)}

)->pack;

MainLoop;



sub do_print {

my ($widget) = @_;

my $entered = $widget -> get();

print "The string "$entered" was entered.\n";

}

 
 
标签: 内容 , 获取 , FAQ , NT , Perl 打印本文
 
 
  热点搜索
 
 
 



Valid XHTML 1.0 Transitional
Copyright ©2005 - 2008 Rdxx.Com,All Rights Reserved
收藏本页
收藏本站