按下“后退”按钮时怎么能关闭win2?
#!/usr/bin/env perl
use warnings; use 5.012;
use Curses::UI;
$Curses::UI::debug = 0;
my $list = [ qw( Use the libraries from distribution instead of system ) ];
my %hash; my $y=0; my $x_1=0; my $width_1=14; my $x_2=16; my $width_2=30;
my $cui = new Curses::UI( -color_support => 1 );
my $win1 = $cui->add( "win1", 'Window', );
for my $entry ( @$list ) {
$win1->add( undef, 'TextEntry', -x => $x_1, -y => $y, -width => $width_1,
-text => $entry, -focusable => 0, -readonly => 1, );
$hash{$entry} = $win1->add( $entry, 'TextEntry', -x => $x_2, -y => $y,
-width => $width_2, -focusable => 1, -readonly => 0, );
$y++;
}
my $but1 = $win1->add( "addbutton1", 'Buttonbox',
-buttons => [ { -label => "< OK >", -onpress => \&add } ],
-x => 5, -y => $y + 2 );
sub add {
my $y = 0;
my $win2 = $cui->add( "win2", 'Window', );
for my $entry ( @$list ) {
my $input = $hash{$entry}->get();
$win2->add( undef, 'TextEntry', -x => $x_1, -y => $y, -width => $width_1,
-text => $entry, -focusable => 0, -readonly => 1, -bg => 'cyan' );
$win2->add( $y, 'TextEntry', -x => $x_2, -y => $y, -width => $width_2,
-text => $input, -focusable => 0, -readonly => 1, -bg => 'cyan' );
$y++;
}
my $but2 = $win2->add( "addbutton2", 'Buttonbox',
-buttons => [{ -label => "< Back >", ###
-onpress => sub{ $win1->focus() }}], -x => 5, -y => $y + 2 );
sub add2 { $win1->focus(); };
$win2->focus();
}
$cui->mainloop;
答案 0 :(得分:1)
在$ cui上调用delete方法。
@@ -32,7 +32,7 @@
}
my $but2 = $win2->add( "addbutton2", 'Buttonbox',
-buttons => [{ -label => "", ###
- -onpress => sub{ $win1->focus() }}], -x => 5, -y => $y + 2 );
+ -onpress => sub{ $win1->focus(); $cui->delete('win2') }}], -x => 5, -y => $y + 2 );
sub add2 { $win1->focus(); };
$win2->focus();
}