How to close a window in Perl / Tk?

In my Perl / Tk script, I opened two windows. After a certain button click, I want to close one of them. How can i do this? Here is what I still have:

$main = new MainWindow;
$sidebar = $main->Frame(-relief => "raised", 
                        -borderwidth => 2)
                ->pack (-side=>"left" ,
                        -anchor => "nw", 
                        -fill   => "y");
$Button1 = $sidebar -> Button (-text=>"Open\nNetlist", 
                               -command=>  \&GUI_OPEN_NETLIST) 
                    ->pack(-fill=>"x");
MainLoop;

sub GUI_OPEN_NETLIST
{
    $component_dialog = new MainWindow;
    $Button = $component_dialog -> Button (-text=>"Open\nNetlist", 
                                           -command=>  **close new window**) 
                                ->pack(-fill=>"x"); 
    MainLoop;
}
+3
source share
1 answer

$component_dialog->destroy -command. , , , . withdraw , , , . . Dialog DialogBox , . , , , .

MainLoop. GUI_OPEN_NETLIST , MainLoop , MainLoop, , .

, , , .

use strict;
use warnings;

my $main = new MainWindow;
my $sidebar = $main->Frame(-relief => "raised", 
                        -borderwidth => 2)
                ->pack (-side=>"left" ,
                        -anchor => "nw", 
                        -fill   => "y");
my $Button1 = $sidebar -> Button (-text=>"Open\nNetlist", 
                               -command=>  \&GUI_OPEN_NETLIST) 
                    ->pack(-fill=>"x");
my $component_dialog = $main->Dialog( -buttons => [ 'Close' ], );

MainLoop;

sub GUI_OPEN_NETLIST
{
    $component_dialog->Show();
}

, , MainWindow Toplevel, MainWindow. A Toplevel , MainWindow , MainWindow MainWindow.

+2

Source: https://habr.com/ru/post/1747355/


All Articles