#!perl
use strict;
use Tk;
my $message;
my $mw1 = MainWindow->new;
$mw1->configure(-title=>"perl GUI",
-background=>'light grey');
$mw1->geometry('400x245+300+100');
my $fr1 = $mw1->Frame( -relief=>'raised',
-borderwidth=>2,
-background=>'light grey')
->pack(-side=>'top', -fill=>'x');
$fr1->Label(-textvariable=>\$message)
->pack(-side=>'left');
$fr1->Button(-text=>'Exit',
-command=>sub{exit})
->pack(-side=>'right');
$mw1->Label(-text=>'Use this button to pop another window',
-background=>'light grey')
->pack(-side=>'top', -fill=>'x');
my $fr2 = $mw1->Frame(-relief=>'raised',
-borderwidth=>2,
-background=>'light grey')
->pack(-side=>'top');
$fr2->Button(-text=>'Pop another window',
-command=>\&new_win )
->pack(-side=>'bottom');
MainLoop;
#----------------------------------------------------------
sub new_win
{
$message = "Popped a second window";
my $mw2 = MainWindow->new;
$mw2->configure(-title=>"perl GUI",-background=>'light grey');
$mw2->geometry('100x100+100+100');
$mw2->Button(-text=>'OK',
-command=>sub{ $mw2->destroy;
$message = 'Closed the Window.'; } )
->pack(-side=>'bottom');
}