在 Perl/Tk 中按下按钮后如何清除 GUI 中的输入小部件
use Tk;
$filename = 'configuration.txt';
$mw = MainWindow->new;
$mw->geometry("500x250");
$f = $mw->Frame->pack(-side => 'bottom');
$f->Button(-text => "Exit",-command => sub { exit; })->pack(-side => 'left');
$f->Button(-text => "Save",-command => \&save_file)->pack(-side => 'left');
$t = $mw->Scrolled("Text", -width => 40, -wrap => 'none')->pack(-expand => 1, -fill => 'both');
foreach (qw/IP_ADDRESS_SS PORT_NUMBER_CLIENT PROTOCOL_CLIENT PORT_NUMBER_SERVER PROTOCOL_SERVER/)
{
$w = $t->Label(-text => "$_:", -relief => 'groove', -width => 30);
$t->windowCreate('end', -window => $w);
$w = $t->Entry(-width => 20, -textvariable => \$info{$_});
$t->windowCreate('end', -window => $w);
$t->insert('end', "\n");
}
$t->configure(-state => 'disabled'); # disallows user typing
my $clear_text = $f->Button(-text => "Clear Text",-command => \&clear_entry)->pack(-side => 'left',
-anchor=>'se',
);
MainLoop;
##### Subroutine #####
sub save_file
{
print"$filename\n";
$info = "Saving '$filename'";
open (FH, ">$filename");
print FH $t->get("1.0", "end");
$info = "Saved.";
}
sub clear_entry
{
$w->delete('0', 'end');
}
这是使用标签和输入小部件进行简单数据输入的 Perk Tk 程序
在这里,我想要的是,如果单击明文按钮,我想清除输入小部件中的所有条目, 请帮助如何做到这一点
谢谢你! 兰吉斯
use Tk;
$filename = 'configuration.txt';
$mw = MainWindow->new;
$mw->geometry("500x250");
$f = $mw->Frame->pack(-side => 'bottom');
$f->Button(-text => "Exit",-command => sub { exit; })->pack(-side => 'left');
$f->Button(-text => "Save",-command => \&save_file)->pack(-side => 'left');
$t = $mw->Scrolled("Text", -width => 40, -wrap => 'none')->pack(-expand => 1, -fill => 'both');
foreach (qw/IP_ADDRESS_SS PORT_NUMBER_CLIENT PROTOCOL_CLIENT PORT_NUMBER_SERVER PROTOCOL_SERVER/)
{
$w = $t->Label(-text => "$_:", -relief => 'groove', -width => 30);
$t->windowCreate('end', -window => $w);
$w = $t->Entry(-width => 20, -textvariable => \$info{$_});
$t->windowCreate('end', -window => $w);
$t->insert('end', "\n");
}
$t->configure(-state => 'disabled'); # disallows user typing
my $clear_text = $f->Button(-text => "Clear Text",-command => \&clear_entry)->pack(-side => 'left',
-anchor=>'se',
);
MainLoop;
##### Subroutine #####
sub save_file
{
print"$filename\n";
$info = "Saving '$filename'";
open (FH, ">$filename");
print FH $t->get("1.0", "end");
$info = "Saved.";
}
sub clear_entry
{
$w->delete('0', 'end');
}
This is the perk Tk program for simple data entry using label and entry widgets
Here,what i want is if click the clear text button i want to clear all the entry in the entry widget,
Plz help how to do this
Thanking u !
Ranjith
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
一种方法是保存条目对象,以便您可以在clear_entry() 子例程中引用它们。
One way is to save off the entry objects so you can reference them in the clear_entry() subroutine.