in reply to $widget->withdraw

It's a common mistake in Tk, to use while loops, or sleep statements. These block the gui. Your main misunderstanding, is that you think that withdraw destroys a widget and all it contains. Withdraw just removes it from being mapped onto the screen, it still exists behind the scenes and can be running. The following code is a quick fix
#!/usr/bin/perl use warnings; use strict; use Tk; my $mw = tkinit; my $tl = $mw->Toplevel(-title=>"Stupid Program"); my $text = $tl->Text()->pack(); my $flag = 0; my $cancel_btn= $tl->Button(-text=>"Cancel", -command=> sub { $flag = 1; $tl->withdraw })->pack(-side =>'left', -expand=>1, -anchor => 'center'); + my $do_btn= $tl->Button(-text=>"Start", -command=> sub { while (<DATA>){ # process data # output to a text widget if($flag){last} $text->insert('end',"$_\n"); $text->update; $mw->after(1000); } })->pack(-side =>'left', -expand=>1, -anchor => 'center'); + MainLoop; __DATA__ 1 2 3 4 5 6 7 8 9 10
You could also do it without a flag, using the ismapped method.
#!/usr/bin/perl use warnings; use strict; use Tk; my $mw = tkinit; my $tl = $mw->Toplevel(-title=>"Stupid Program"); my $text = $tl->Text()->pack(); my $cancel_btn= $tl->Button(-text=>"Cancel", -command=> sub { $tl->withdraw })->pack(-side =>'left', -expand=>1, -anchor => 'center'); + my $do_btn= $tl->Button(-text=>"Start", -command=> sub { while (<DATA>){ # process data # output to a text widget if(! ismapped $tl){last} $text->insert('end',"$_\n"); $text->update; $mw->after(1000); } })->pack(-side =>'left', -expand=>1, -anchor => 'center'); + MainLoop; __DATA__ 1 2 3 4 5 6 7 8 9 10

I'm not really a human, but I play one on earth. flash japh

Replies are listed 'Best First'.
Re^2: $widget->withdraw
by Anonymous Monk on Jun 02, 2006 at 17:04 UTC
    Zentara, You are a Saint! Thanks for the clarification. I would apply the ismapped function.
      No, I'm not a Saint.......just a happy Abbot. ;-)

      I'm not really a human, but I play one on earth. flash japh