in reply to Re: how to prevent more than 1 tk Toplevel windows from opening
in thread how to prevent more than 1 tk Toplevel windows from opening

Thanks for your suggestion. I tested your code and I found one problem. If the user close the TopLevel window by clicking the X on the window's top-right corner instead of clicking the Close button., the user can not open any Toplevl window any more. Please help. Thanks
  • Comment on Re^2: how to prevent more than 1 tk Toplevel windows from opening

Replies are listed 'Best First'.
Re^3: how to prevent more than 1 tk Toplevel windows from opening
by henry888 (Initiate) on May 18, 2008 at 00:52 UTC
    found solution myself for my second question. OnDestroy will do the trick.. Thanks, perlmonks is a very helpful place.
    ====================== #!/usr/bin/perl use warnings; use strict; use Tk; my $tl; 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=>'disabled'); if ( !Exists( $tl ) ) { $tl = $mw->Toplevel(); $tl ->OnDestroy( sub { $tl->withdraw; $spawn_button->configure(-state=>'normal'); } ); $tl->geometry('300x100+100+100'); $tl->title( "Toplevel" ); $tl->Button( -text => "Close", -command => sub { $tl->withdraw; $spawn_button->configure(-state=>'normal'); } )->pack; } else { $tl->deiconify(); $tl->raise(); } } ===============
Re^3: how to prevent more than 1 tk Toplevel windows from opening
by zentara (Cardinal) on May 18, 2008 at 14:11 UTC
    Probably a better way than using onDestroy, is to just ignore the signal.
    if ( !Exists( $tl ) ) { $tl = $mw->Toplevel(); $tl->protocol('WM_DELETE_WINDOW' => sub { print "do nothing here\n"; }); ......

    I'm not really a human, but I play one on earth. Cogito ergo sum a bum