$tl = $mw->Toplevel(-title=>"Stupid Program"); while (){ process data output to a text widget } my $cancel_btn=$action_frame->Button(-text=>"Cancel", -command=> sub { $tl->withdraw })->pack(-side =>'left', -expand=>1, -anchor => 'center');