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

In the perl tk code below, i use a create_tab subroutine to create several tabs (tk notebooks)

As the number of tabs grew i had a need to add a main window scroll bar using mw->Scrolled which would help me move to other tabs beyond the view of main window.

The addition of this scroll bar now makes my tabs not fill the main window height completely while it fits the main window width.

Would any of you monks be able to let me know what is wrong with my code which causes the vertical fit issue and how to solve it?

#!/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 pages 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 $_"; $_ = create_tab("$title"); } ### 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); my $t = $tn->Scrolled("Text", -scrollbars => "e", -wrap => 'none') +->pack(-expand => 1, -fill => 'both'); $t->tagConfigure ('bold', -font => [ -size => 0, -weight => 'bold' + ]); return $t; } MainLoop;

Replies are listed 'Best First'.
Re: Perl Tk Notebook not filling main window height
by Discipulus (Canon) on May 24, 2017 at 11:37 UTC
    hello,

    your question seems very similar to Re^2: why is the size of notebooks area smaller than main window (Tk).. normally is preferable to continue the old thread instead of creating a new one..

    Anyway.. even if i have not a solution I have some suggestion: first our is not appropriate in the example: my is better.

    You also repack two times the same widget, creating a bit of confusion; also the withdraw / Popup is avoidable.

    Then a smaller example will be better to play with. You can add Tk::WidgetDump to see how each part of your Tk program is configured, I find it very useful.

    In my smaller example seems that anything i do the Tk::NotePad object has a limited size with or without -fill => 'both', -expand => 1

    Can be this related to the fact (in the docs) that: The options -width and -height do not work. ?

    #!/usr/bin/perl # THIS DOES NOT RESOLVE YOR ISSUE, but is simpler to play with use warnings; use strict; use Tk; use Tk::NoteBook; use Tk::Pane; my $mw = MainWindow->new; $mw->packPropagate(0);#->geometry('300x200'); my $frame = $mw->Scrolled( 'Frame',-background=>'purple', -scrollbars +=> "s") ->pack(-expand=>1, -fill=>'both', -anchor=>' +nw'); my $nb_widget = $frame->NoteBook->pack(-expand=>1, -fill=>'both'); for (1..20){ $nb_widget->add("page$_", -label=>"PAGE $_") ->Scrolled("Text", -scrollbars => "e", -wrap = +> 'none') ->pack(-expand => 1, -fill => 'both');; } MainLoop;

    L*

    There are no rules, there are no thumbs..
    Reinvent the wheel, then learn The Wheel; may be one day you reinvent one of THE WHEELS.
      Of course our is appropriate
Re: Perl Tk Notebook not filling main window height
by tybalt89 (Monsignor) on May 24, 2017 at 18:37 UTC

    Like this?

    #!/usr/bin/perl # http://perlmonks.org/?node_id=1191061 use strict; use warnings; use Tk; use Tk::NoteBook; use Tk::Pane; our $mw = MainWindow->new; $mw->geometry("800x1000"); # Create the NoteBook and add pages my $pane = $mw->Scrolled( 'Pane', -scrollbars => 'osoe', -bg => 'green', -sticky => 'nsew', )->pack( -fill=>'both', -expand=>1); my $n = $pane->Scrolled('NoteBook', -scrollbars => 'os', #-dynamicgeometry => 'true', )->pack( -fill => 'both', -expand => 1); create_tab("mytab $_") for 1..20; sub create_tab { my $tabname = shift; my $tn = $n->add($tabname, -label => $tabname, -underline => 0); my $t = $tn->Text(-wrap => 'none', )->pack(-expand => 1, -fill => 'both'); $t->tagConfigure ('bold', -font => [ -size => 0, -weight => 'bold' + ]); return $t; } MainLoop;

      Thank you all for responding to my query

      The usage of sticky solution suggested by tybalt89 helped me.

      Here are the changes i made to the original code i pasted when i started this thread to get a neat solution.

      1. added use Tk::Pane; 2. Modified Canvas in mw->Scrolled to Pane 3. Added -sticky => 'nsew' in mw->Scrolled 4. Commented usage of $canvas->createWindow, ->update and ->configure 5. Modified occurrence of $canvas to $pane to ensure variable name matches usage
      Hi, I have to say your modification works perfect.... it looks like the better use of -sticky, :-)
      You had ,-sticky => 'nsew', which makes alot of sense for what the widget is doing.

      I'm not really a human, but I play one on earth. ..... an animated JAPH
Re: Perl Tk Notebook not filling main window height
by zentara (Cardinal) on May 24, 2017 at 15:58 UTC
    Would any of you monks be able to let me know what is wrong with my code which causes the vertical fit issue and how to solve it?

    Hi, I have a hard time trying to understand why you create a canvas, add notebooks to the canvas, and add windows into the canvas to hold the notebooks, $mw->Popup, $mw->withdraw.???? Did you just cut-copy-and-paste a bunch of code together and hoped it worked? :-)

    Notebooks are hard to get working properly when it comes to resizing, see: perltk autoresize following users resize

    Here is a hack to make it work somewhat correctly, just make your widgets larger, I upped them to 1000. I also didn't pack them until just before the Mainloop is called. This gives them time to size themselves before being displayed.

    #!/usr/bin/perl use warnings; use strict; use Tk; use Tk::NoteBook; use Tk::Pane; my $mw = MainWindow->new; $mw->geometry("600x400"); my $pane = $mw->Scrolled('Pane',-height => 1000,-bg=>'black', -scrollb +ars => "osoe"); my $n = $pane->NoteBook(); for ( 1 .. 20 ){ my $title = "mytab $_"; $_ = create_tab("$title"); } #pack widgets after being fully built $n->pack(-expand=> 1, -fill=>'both', -expand=>1, -anchor=>'nw',-side = +> 'top'); $pane->pack(-fill => 'both', -expand => 1); $mw->update; MainLoop; sub create_tab { my $tabname = shift; my $tn = $n->add($tabname, -label => $tabname, -underline => 0, #-raisecmd =>sub{ $mw->update} ); my $t = $tn->Scrolled("Text", -scrollbars => "onow", -height=> 100 +0, -bg=> 'lightseagreen', -wrap => 'none')->pack(-expand => 1, -fill => 'both', -anch +or=> 'nw'); $t->tagConfigure ('bold', -font => [ -size => 20, -weight => 'bold +' ]); for (1..1000){$t->insert('end',$tabname. "_$_\n",['bold'])}; return $t; }

    I'm not really a human, but I play one on earth. ..... an animated JAPH