Clachair has asked for the wisdom of the Perl Monks concerning the following question:
This works OK, except for Line 9 which passes to the subroutine whatever was in $fn the last time it was used, regardless of which menu item was selected. I've tried all sorts of alternatives but nothing works as intended, and unless some clever monk has a really ingenious suggestion I think I'm going to be stuck with several dozen short subroutines and a hash table. I've searched, but cannot find an equivalent to the cget instruction used in listboxes.1. #Read a list of files from the cur/wkg/dir and insert them in the 'Load' menu bar ; 2. opendir(DIR, $dir); 3. @dirList = readdir(DIR); 4. closedir(DIR); 5. # Sort the list; 6. @dirList = sort @dirList; 7. foreach $fn (@dirList) { 8. $Load_mb -> command(-label => $fn, 9. -command => sub {&Load ($fn)} ); 10. } ; # End foreach; 11. 12. sub Load { 13. $Title = "Loading $_[0] "; 14. $Main_Window -> title($Title); 15. #Do something clever with whichever menu item was requested; 16. }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Perl/Tk Menus
by danger (Priest) on Jun 09, 2001 at 04:57 UTC | |
by Clachair (Acolyte) on Jun 09, 2001 at 09:14 UTC | |
|
Re: Perl/Tk Menus
by ariels (Curate) on Jun 09, 2001 at 16:01 UTC |