#!/usr/bin/perl use strict; use warnings; use Tk; my $t1; my $mw = MainWindow->new; $mw->title( "MainWindow" ); my $spawn_button = $mw->Button( -text => "Toplevel", -command => \&do_Toplevel )->pack; MainLoop; sub do_Toplevel { $spawn_button->configure(-state => 'normal'); if ( !Exists( $t1 ) ) { $t1 = $mw->Toplevel(); sub { $t1->withdraw; $spawn_button->configure(-state => 'disabled'); $t1->geometry('300x100+100+100'); $t1->title( "Toplevel" ); $t1->Button( -text => "Close", -command => sub { $t1->withdraw; $spawn_button->configure(-state => 'normal'); } )->pack; } } else { $t1->deiconify(); $t1->raise(); } }