in reply to creating multiple widgets at runtime
You said "at runtime", which sort of indicating that you may not know what buttons you need at compilation time. If that is the case, the following example might be useful.
use strict; use warnings; use Tk; my @files = ("File1.txt", "File2.txt", "File3.txt"); #in real life, th +is might not be fixed my @buttons; my $main = MainWindow->new(); my $load = $main->Button(-text => "Load", -command => \&load_buttons)- +>pack(); my $unload = $main->Button(-text => "Unload", -command => \&unload_but +tons)->pack(); MainLoop; sub load_buttons { for my $file (@files) { push @buttons, $main->Button(-text => "Open $file", -command = +> sub{`notepad $file`})->pack(); } } sub unload_buttons { while (@buttons) { my $button = pop @buttons; $button->destroy(); } }
|
|---|