Sisk has asked for the wisdom of the Perl Monks concerning the following question:
#!/usr/bin/perl use Tk; use Switch; # Variables for emulators $snesCommand="zsnes"; $genesisCommand="dgen"; $nesCommand="nestra"; $snesDirectory="~/roms/nes/"; $genesisDirectory="~/roms/genesis/Roms/"; $snesDirectory="~/roms/snes/Roms/"; $mw=MainWindow->new(-title=>"Launcher"); #Main window elements $systemPick=$mw->Optionmenu(-command=>\&changeList, -variable=>\$system); $systemPick->addOptions("SNES","NES","Genesis"); $opt=$mw->Scrolled("Listbox",-selectmode=>'single', -scrollbars=>"se"); $go=$mw->Button(-text=>"Launch Game", -command=>\&gogo); # Geometry $systemPick->pack(); $opt->pack(-expand=>1,-fill=>"both"); $go->pack(); sub changeList { $opt->delete(0,'end'); switch ($system) { case "SNES" { $command=$snesCommand; $directory=$snesDirectory; @dir=glob($snesDirecotry); foreach my $file(@dir) { $file=~s/$directory//; $opt->insert('end',$file); } } case "NES" { $command=$nesCommand; $directory=$nesDirectory; @dir=glob($nesDirecotry); foreach my $file(@dir) { $file=~s/$directory//; $opt->insert('end',$file); } } case "Genesis" { $command=$genesisCommand; $directory=$genesisDirectory; @dir=glob($genesisDirecotry); foreach my $file(@dir) { $file=~s/$directory//; $opt->insert('end',$file); } } } } sub gogo { my $selected=$opt->get($opt->curselection()); system("$command $directory$selected"); } &changeList; MainLoop;
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Tk Listbox problem
by Erez (Priest) on Feb 19, 2009 at 08:17 UTC | |
Re: Tk Listbox problem
by Anonymous Monk on Feb 19, 2009 at 04:06 UTC | |
by Sisk (Novice) on Feb 19, 2009 at 06:04 UTC |