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