Curses::UI - 如何关闭窗口?

发布于 2024-10-05 20:21:31 字数 1749 浏览 2 评论 0原文

按“后退”按钮时如何关闭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;

How could I close win2 when pressing the "Back"-button?

#!/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;

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

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

发布评论

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

评论(1

抠脚大汉 2024-10-12 20:21:31

调用 $cui 上的删除方法。

@@ -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();
 }

Call the delete method on $cui.

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