use strict; use warnings; use Tk; my $mw = MainWindow->new(); $mw->Button(-text => 'Open Toplevel', -command => sub { my $single_tl = $mw->Toplevel(); $single_tl->Button(-text => 'Close', -command => sub { $single_tl->destroy(); }, )->pack(); $single_tl->grab(); }, )->pack(); $mw->Button(-text => 'Exit', -command => sub { exit })->pack(); MainLoop;