use strict; use warnings; use Tk; my $mw = MainWindow->new(); my $single_tl; $mw->Button(-text => 'Open Toplevel', -command => sub { if (Exists($single_tl)) { $mw->messageBox(-message => 'Already Open'); } else { $single_tl = $mw->Toplevel(); $single_tl->Button(-text => 'Close', -command => sub { $single_tl->destroy(); }, )->pack(); } }, )->pack(); $mw->Button(-text => 'Exit', -command => sub { exit })->pack(); MainLoop; #### 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;