#! /usr/bin/perl -w use strict; use Tk; use Tk::Toplevel; ################ # Main Routine # ################ my $w; $w->{main} = MainWindow->new(-title => 'Tk Hash'); $w->{main}->Button(-text => "Click me to open a new toplevel", -command => [ \&new_tl, $w ])->pack; $w->{main}->Button(-text => "Click me to test for other button", -command => [ \&test_tl, $w ])->pack; MainLoop; exit; ############### # Subroutines # ############### sub new_tl { my $w = shift; if ( not Tk::Exists $w->{toplevel} ) { $w->{toplevel} = $w->{main}->Toplevel( -takefocus => 1, -title => 'Top Level' ); $w->{testbutton} = $w->{toplevel}->Button(-text => 'Null button'); } else { $w->{toplevel}->deiconify(); $w->{toplevel}->raise(); $w->{toplevel}->focusForce(); } } sub test_tl { my $w = shift; if ( Tk::Exists $w->{testbutton} ) { print "testbutton exists\n"; } else { print "testbutton does not exist\n"; } }