CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Intermediate: Multi Menu, multi-function Tk Ap: Edit Log



PapaGeek
User

Mar 11, 2014, 11:46 PM


Views: 7340
Multi Menu, multi-function Tk Ap

 
On Edit: My second post shows the same code broken into individual Perl menu files.

Well, Iíve switches to Tk, and of course every action now has a new name!

Is this the correct Tk way to create a main menu which calls various sub menus which control their own actions? I only want one menu visible at a time. If you are doing A you canít start or see B.

Any suggestions on making this more Perlish or better Tk widgets to use is appreciated.

If this is correct, my next step will be to break up the code into separate Perl files for each menu and action.



Code
use Modern::Perl '2013';  
use Tk;

my $mw = new MainWindow;
$mw->geometry("200x100");
my $lblMsg = $mw -> Label(-text=>"Work with sub windows")-> grid();
my $openMenu1 = $mw -> Button(-text=>"See Option 1",
-command =>\&showOption1)-> grid();
my $openMenu2 = $mw -> Button(-text=>"See Option 2",
-command =>\&showOption2)-> grid();
my $endProgram = $mw -> Button(-text=>"Exit Program",
-command =>\&endProgram)-> grid();

my $option1 = new MainWindow;
$option1->geometry("200x200");
my $lblMsg1 = $option1 -> Label(-text=>"Program Option 1")-> grid();
my $doTask1 = $option1 -> Button(-text=>"Perform Task 1",
-command =>\&Task1)-> grid();
my $btnPostpone1 = $option1 -> Button(-text=>"Return to Main",
-command =>\&showMainFrom1)-> grid();
$option1-> withdraw();

my $option2 = new MainWindow;
$option2->geometry("250x150");
my $lblMsg2 = $option2 -> Label(-text=>"Program Option 2")-> grid();
my $doTask2 = $option2 -> Button(-text=>"Perform Task 2",
-command =>\&Task2)-> grid();
my $btnPostpone2 = $option2 -> Button(-text=>"Return to Main",
-command =>\&showMainFrom2)-> grid();
$option2-> withdraw();

MainLoop;

sub showOption1{
$mw-> withdraw();
$option1->deiconify();
$option1->raise();
}
sub showOption2{
$mw-> withdraw();
$option2->deiconify();
$option2->raise();
}
sub showMainFrom1{
$option1-> withdraw();
$mw->deiconify();
$mw->raise();
}
sub showMainFrom2{
$option2-> withdraw();
$mw->deiconify();
$mw->raise();
}
sub Task1{
say "doing task 1";
}sub Task2{
say "doing task 2";
}

sub endProgram{
exit;
}



(This post was edited by PapaGeek on Mar 12, 2014, 7:34 AM)


Edit Log:
Post edited by PapaGeek (User) on Mar 12, 2014, 7:34 AM


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives