madhusudhan_s has asked for the wisdom of the Perl Monks concerning the following question:

Hi,

I am trying to write a program which has many notebooks and i found a reference code from the web as below which is exactly what i want. When i make the main window size 870x1000 i notice that the area where the notebooks are present is smaller than the main window. How should i modify this code such that the notebooks are as big as the main window?
#!/usr/bin/perl use strict; use warnings; use Tk; use Tk::NoteBook; our $mw = MainWindow->new; $mw->geometry("870x1000"); my $canvas = $mw->Scrolled('Canvas',-bg=>'red')->pack; our $nb = $canvas->NoteBook; ### add 20 tabs to notebook for ( 1 .. 20 ){ my $title = "Untitled ($_)"; $nb->add( $_, -label => $title ); } ### embed the notebook widget into the canvas my $nb_in_canvas = $canvas->createWindow( 0,0,-window => $nb,-anchor = +> 'nw' ); $canvas->update; ### the whole notebook is larger than what can be initially displayed ### so we'll have to sroll it later on in the program $canvas->configure(-scrollregion => [0,0,$nb->reqwidth,$nb->reqheight] +); MainLoop;

Replies are listed 'Best First'.
Re: why is the size of notebooks area smaller than main window
by kcott (Archbishop) on May 22, 2017 at 05:28 UTC

    G'day madhusudhan_s,

    Welcome to the Monastery.

    I just tried your code. Modifying

    ...->pack;

    to be

    ...->pack(-fill => 'both', -expand => 1);

    achieves what you ask.

    See Tk::pack for more information on those, and other, options of this geometry manager.

    — Ken

      Thank you Ken for that solution. It works!!

      Now i added new subroutines to create tabs and add certain things on the tabs. when this program is run i notice that the tab content gets restricted vertically while horizontally it fits the main window width.

      I realized that this is due to pack present in the subroutine create_tab. It so happens that i need the tab scrollbar and a main window scroll bar.

      When i comment this pack my content and the tab and scrollbars vanish. How should i modify the program to have a vertical fit of the tab to main window height and contents on the tab seen.

      Sorry if my question are too basic.

      #!/usr/bin/perl use Tk; #use strict; require Tk::NoteBook; require Tk::LabEntry; require Tk::Scrollbar; our $mw = MainWindow->new; $mw->geometry("800x1000"); my $canvas = $mw->Scrolled('Canvas', -scrollbars => "s")->pack(-fill = +> 'both', -expand => 1); $mw->withdraw(); $mw->Popup; # Create the NoteBook and add 2 pages, which are really # Frames with tabs. Given that, we create LabEntry # widgets and pack them as usual. our $n = $canvas->NoteBook(-dynamicgeometry => 'true')->pack( -fill=>' +both', -expand=>1); $n->pack( -expand => "yes", -fill => "both", -side => "top" ); for ( 1 .. 20 ){ my $title = "mytab $_"; #$n->add( $_, -label => $title ); $_ = create_tab("$title"); create_tab_labentry($_, \$folder_name, "folder name: "); } ### embed the notebook widget into the canvas my $nb_in_canvas = $canvas->createWindow( 0, 0, -window => $n, -anchor + => 'nw' ); $canvas->update; ### the whole notebook is larger than what can be initially displayed ### so we'll have to sroll it later on in the program $canvas->configure( -scrollregion => [0,0,$n->reqwidth,$n->reqheight]) +; sub create_tab { my $tabname = shift; my $tn = $n->add($tabname, -label => $tabname, -underline => 0); $t = $tn->Scrolled("Text", -scrollbars => "e", -wrap => 'none')->p +ack(-expand => 1, -fill => 'both'); $t->tagConfigure ('bold', -font => [ -size => 0, -weight => 'bold' + ]); return $t; } sub create_tab_labentry { my $tabname = shift; my $fc_address = shift; my $field_label = shift; $w = $tabname->Button(-text => $field_label, -relief => 'raised', +-width => 66); $tabname->windowCreate('end', -window => $w); $w = $tabname->Entry(-width => 35, -textvariable => $fc_address); $tabname->windowCreate('end', -window => $w); $tabname->insert('end', "\n"); } MainLoop;
        Hi, I always love seeing people use Tk. It's a small-self-contained toolkit which allows you to do may things. Tk and Perl are a perfect low resource toolkit.

        Sorry if my question are too basic.

        I don't really understand what you are trying to do with the scrollbars, but most applications need this sort of canvas-linked scrollbars. See: Re: I seek illumination and knowledge


        I'm not really a human, but I play one on earth. ..... an animated JAPH
Re: why is the size of notebooks area smaller than main window (Tk)
by hippo (Archbishop) on May 22, 2017 at 07:42 UTC
    i found a reference code from the web

    You found it from this post by brother zentara from 2003.