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: Re: [PapaGeek] Multi Menu, multi-function Tk Ap: Edit Log



FishMonger
Veteran / Moderator

Mar 12, 2014, 7:43 AM


Views: 5571
Re: [PapaGeek] Multi Menu, multi-function Tk Ap

Rather than creating multiple independent MainWindow objects, it's preferable to use Tk::Toplevel to create the child windows.
http://search.cpan.org/~srezic/Tk-804.032/pod/Toplevel.pod

Here's an example pulled from a similar question on perlmonks.

Code
#!/usr/bin/perl 
use warnings;
use strict;
use Tk;

my $mw = tkinit;

my $top = $mw->Toplevel();
$top->configure(-title=>'Fruit Menu');

my $ls_show_fruit = $top->Scrolled('Listbox',
-relief=>'groove',
-width=>'20',
-height=>5,
-scrollbars=>'se' ,
-selectmode =>'single'
)->pack(-side=>'left',-anchor=>'sw');

$ls_show_fruit->insert('end',"apples");
$ls_show_fruit->insert('end',"oranges");
$ls_show_fruit->insert('end',"peaches");

$top->Button(-text => 'Ok',
-command => sub{
$top->withdraw;
$mw->deiconify;
$mw->raise;

})->pack();

$top->withdraw;


$mw->Button(-text=> 'select_fruit',
-command => sub{
$top->deiconify;
$top->raise;
$mw->withdraw;

})->pack;

MainLoop;


While it is common to use a button widget to create a child window, IMO it's better to use Tk::Menu to create a standard menubar with links that create the child windows and then use button widgets to preform specific tasks within the window.
http://search.cpan.org/~srezic/Tk-804.032/pod/Menu.pod


(This post was edited by FishMonger on Mar 12, 2014, 7:46 AM)


Edit Log:
Post edited by FishMonger (Veteran) on Mar 12, 2014, 7:46 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