#!/usr/local/bin/perl use strict; use warnings; use Tk; #main window my $mw = MainWindow->new(-title=>'Main Window'); create_widgets($mw); MainLoop(); sub create_toplevel_window { # create toplevel window my $top=$mw->Toplevel(-title=>"Toplevel Window"); # create toplevel frames create_widgets($top); } sub create_widgets { my $thiswindow = shift; my $frame_top = $thiswindow->Frame-> pack(-side=>'top',-fill => 'both', -anchor,'nw'); my $frame_bottom = $thiswindow->Frame-> pack(-side=>'top',-fill => 'both', -anchor,'nw'); my $edit_button = $thiswindow->Button(-text => "Create Toplevel Window",-state => 'normal',-width => 30,-activebackground=>'gray', -command => sub{create_toplevel_window()})->pack (-in => $frame_top,-side=>'top',-padx => 3,-pady => 5); my $mw_close_button = $thiswindow->Button(-text => 'Close',-background=>'gray',-width=>60,-command => sub{$thiswindow->destroy})->pack(-in=>$frame_bottom,-side => 'top',-expand => '0',-fill => 'x'); }