I'm building an app with TK and need a way to dynamically change the contents of the main window. My approach is to place a frame in the window that takes up all of the space, then use subs to clear and fill the frame. When I try this, however, the sub isn't doing anything.
here is my code:
use warnings;
use strict;
use Tk;
### Build Main Window #
my $mainWindow = MainWindow->new;
$mainWindow->title("BNS Cable Customer Managment");
$mainWindow->geometry("800x600");
### Build Menu Bar
my $mainMenu =$mainWindow -> Menu();
$mainWindow -> configure(-menu => $mainMenu);
my $fileM = $mainMenu -> cascade(-label=>"File", -underline=>0, -tearo
+ff => 0);
my $optsM = $mainMenu -> cascade(-label=>"Options", -underline=>0, -te
+aroff => 0);
my $modeM = $mainMenu -> cascade(-label=>"Mode", -underline=>0, -tearo
+ff => 0);
##File Menu
$fileM -> command(-label => "New Property", -underline=>0 );
$fileM -> command(-label => "Logout", -underline=>0 );
$fileM -> separator();
$fileM -> command(-label =>"Exit", -underline => 1,
-command => sub { exit } );
##Options menu
$optsM -> command(-label => "Preferences", -underline=>0 );
##Mode Menu
$modeM -> command(-label => "Property Centric",
-underline=>0,
-command => \&propCen);
$modeM -> command(-label => "Task Centric", -underline=>0 );
#### Now the main Content
my $content = $mainWindow->Frame;
$content->pack(-fill => 'both',
-expand => 1,
-pady => 10,
-padx => 10);
MainLoop;
sub propCen {
$content->packForget;
my $propList = $content->Scrolled("Listbox",
-scrollbars=>"e",
-exportselection => 0,
-selectmode => "extended")
->pack( -anchor => 'w',
-fill => 'y',
-expand => 1);
}
If I move the contents of the sub out and into the mainloop, it displays as I want it to.
nevermind..... I wasn't repacking the frame after I 'forgot' it. Saw that as soon as I posted.
While that did work, It's not working as expected.
With that code, the proper contents load correctly, but if I call the sub multiple times in a row, it starts nesting the widgets, instead of destroying and rebuilding.
Am I missing something or is there a better way to go about this?
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.