in reply to creating multiple widgets at runtime

Move MainLoop; outside the while loop:

while(@array) { $file=pop @array; $top->Button(-text => "Click Me",-command => sub{ system "start c:/W +INNT/system32/notepad.exe $file" })->pack(); $x=$x+10; } MainLoop;

Note that c:/WINNT/system32/notepad.exe is not very portable. Use either Notepad $file or just $file (if $file has a .txt extension).


Perl is Huffman encoded by design.

Replies are listed 'Best First'.
Re^2: creating multiple widgets at runtime
by arunmep (Beadle) on Jul 25, 2005 at 03:59 UTC
    thank you GrandFather i am able to get multiple widgets now but i need to have different control for each widget say by clicking each widget i need to open different files.how can i do that

      This works for me:

      use strict; use warnings; use Tk; my @array = ("File1.txt", "File2.txt", "File3.txt"); my $main = MainWindow->new (); while (@array) { my $name=pop @array; $main->Button ( -text => "Open $name", -command => sub{`notepad $name`} )->pack(); } MainLoop;

      Perl is Huffman encoded by design.