in reply to How do I determine if a Tk window exists?
use Tk; use strict; my $tl; #<- Make this avaliable for testing globally. my $mw = MainWindow->new; $mw->title("MainWindow"); $mw->Button(-text => "Toplevel", -command => \&do_Toplevel)->pack( ); $mw->Button(-text => "test Toplevel", -command => \&test_toplevel)->pa +ck( ); MainLoop; sub do_Toplevel { if (! Exists($tl)) { $tl = $mw->Toplevel( ); $tl->title("Toplevel"); $tl->Button(-text => "Close", -command => sub { $tl->withdraw })->pack; } else { $tl->deiconify( ); $tl->raise( ); } } sub test_toplevel { if ( Exists($tl)) { print "Top level is here\n"; } else { print "Top level is gone\n"; } }
|
|---|