如何在win32-gui perl中获取文本字段数据

时间:2010-04-05 04:40:36

标签: perl textfield

您好我想将文本字段数据存储在变量中,但我的代码无效 这是我的代码

use Win32::GUI qw<>;

my $W1 = Win32::GUI::Window->new(
 -name  => "W1",
 -title => "First Window",
 -pos   => [ 100, 100 ],
 -size  => [ 300, 200 ],
);

$W1->AddButton(
 -name => "ButtonW1",
 -text => "Enter Chipname",
 -pos  => [ 87, 100 ],
 #-ok  => 1,
);

 $W1->AddTextfield(
  -name    => "chipfield",
  -left    =>  20,
  -top     =>  40,
  -width   => 250,
  -height  => 20,
   #  -prompt => ["Mix ",30],
  );

$W1->Show();
Win32::GUI::Dialog();
exit(0);


sub W1_Terminate { return -1; }

sub ButtonW1_Click {
    my $chipname = $W1->chipfield->Text();
    print $chipname;
}

请帮我解决问题enter code here

2 个答案:

答案 0 :(得分:0)

看起来像是一个缓冲问题。添加$ | = 1;在打印$ chipname之前;声明,一切都会好起来的:

my $chipname = $W1->chipfield->Text();
$|=1;
print $chipname;

或者通过改变

来做axeman建议的事情
print $chipname;

print $chipname,"\n";

您可能还想查看一下这篇文章:Suffering from Buffering?

答案 1 :(得分:0)

看起来像是破坏了“Win32 :: GUI :: Window Class”

的处理问题
my $W1 = Win32::GUI::Window->new(
 -name  => "W1",
 -title => "First Window",
 -pos   => [ 100, 100 ],
 -size  => [ 300, 200 ],
);
...

$W1->Show();
Win32::GUI::Dialog();
undef $W1;       <-----Addtion line
exit(0);