#!/usr/bin/perl -w use Tk; use strict; my $MW; my $Array_Index=""; my @Widget_List; my $my_ref; my @file_references ; my $i; $MW = MainWindow->new; push @Widget_List, $MW->title("test box 1"); push @Widget_List, $MW->Label(-text=>"Choose one option", -font=>"courierfont") -> pack; @file_references = ("Ref1", "Ref2", "Ref3", "Ref4"); $i=1; foreach $my_ref (@file_references) { push @Widget_List, $MW->Button(-text => "$my_ref", -command => [ \&do_button, "$my_ref,$i"]) -> pack; $i++; } MainLoop(); sub do_button { my $params; my $widget; $params = shift; (my $ref, $Array_Index) = split (/,/,$params); print "$params\n"; $MW->Label(-text=>"This line will not cause a segfault")->pack; foreach $widget (@Widget_List) { $widget->destroy(); } $MW->Button(-text => "Shutdown and close", -command => [ \&abort_routine]) -> pack; } sub abort_routine{ exit } #### #!/usr/bin/perl use warnings; use strict; use Tk; my $MW = MainWindow->new; $MW->withdraw; $MW->Label(-text=>"This line will not cause a segfault")->pack; $MW->Button(-text => "Shutdown and close", -command => [ \&abort_routine]) -> pack; my $top = $MW->Toplevel(-bg=>'steelblue',-title=>"test box 1"); $top->Label(-text=>"Choose one option", -font=>"courierfont") -> pack; my @file_references = ("Ref1", "Ref2", "Ref3", "Ref4"); my $i=1; foreach my $my_ref (@file_references) { $top->Button(-text => "$my_ref", -command => [ \&do_button, "$my_ref,$i"]) -> pack; $i++; } MainLoop(); sub do_button { my $params; my $widget; $params = shift; (my $ref, my $Array_Index) = split (/,/,$params); print "$params\n"; $top->destroy(); $MW->deiconify; $MW->raise; } sub abort_routine{ exit }