Hello Monks,
The Geometry Manager docs (say, for example that of:
pack) state the following
-in => *$master*
insert the slave(s) at the end of the packing
order for the master window.
This means,
-
packs $widget inside of $master rather than the parent of $widget, which is the default. (Chapter 2: Mastering Perl/Tk -- Oreilly Press).
- Technically, any widget can be a parent of another widget, but life is easier when widgets are children of a Frame, or else we have to use the -in option with pack. (Chapter 11: Frames, MainWindow...)
I'm interested to understand the usefulness of this option with respect to
Tk::NoteBook. In
Tk::NoteBook at a time there is only one active page. i.e. only one page is in a
raised state. Therefore, if each page is to have same set of widgets displayed inside it, then instead of creating the widgets for each page in the
Tk::NoteBook it is simply enough to create the widgets only once and then re-use the same widgets for all the other pages, after all only one page gets displayed at a time.
Here's a small program that attempts at this
BUT FAILS.
use strict;
use Tk;
use Tk::NoteBook;
my $mw = MainWindow->new;
$mw->geometry('100x200');
my $nb = $mw->NoteBook()->pack(-fill => 'both',
-expand => 1);
my $page_tab_01=$nb->add ("TAB-1",
-label=>'TAB-1',
-raisecmd=>\&callback_01);
my $page_tab_02=$nb->add ("TAB-2",
-label=>'TAB-2',
-raisecmd=>\&callback_02);
my $t_button = $page_tab_01->Button(-text=>'OK',
-command=>sub{exit});
MainLoop;
sub callback_01 {
$t_button->packForget;
$t_button->pack(-in=>$page_tab_01);
}
sub callback_02 {
$t_button->packForget;
$t_button->pack(-in=>$page_tab_02); #<---ERROR HERE
}
I get the following error
error:can't pack .notebook.tAB_1.button inside .notebook.tAB_2
Please let me know as to what mistake I'm doing in the above prgram and is there any other method besides this to accomplish the re-use of widgets in different page-tabs.
Thank you very much
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.