in reply to How to set the MainWindow agile to the context in Perl/Tk

G'day Janish,

"Could anyone tell me if Perl/Tk allows flexible window re-size or any other option that could help to resolve this?"

The short answer is: Yes.

A longer, and more useful, answer will depend on the geometry manager you're using. Tk provides these geometry managers:

Read the documentation for whichever one you're using. If it turns out that the geometry manager you're currently using doesn't do what you want, pick another one. Tk::pack is probably the best choice but, as you've shown no code, that's just a guess.

In addition, regardless of the size of the monitor, adding sufficient widgets will eventually exceed the available screen real estate. You may need to add scrollbars to various widgets: these can be made optional so that they only appear when needed. Tk::Pane, a scrollable frame widget, may be a better choice than Tk::Frame. Other scrollable widgets may be a better choice than whatever you're currently using.

If the general information I've provided leads to a solution, that's great. If not, you'll need to provide more specific information to get a more specific answer. This should include a short, self-contained example which reproduces your problem: see How do I post a question effectively? for more details about this.

-- Ken

  • Comment on Re: How to set the MainWindow agile to the context in Perl/Tk

Replies are listed 'Best First'.
Re^2: How to set the MainWindow agile to the context in Perl/Tk
by Janish (Sexton) on May 18, 2015 at 01:42 UTC

    Thank you Ken.

    I'm using TK::NoteBook and wonder if I could add the 'scroll' feature in each tab window to resolve the missing items dealing with monitor resolution issue but is that a limitation to add 'scroll' feature in TK::NoteBoot? Or I have misread that? Thank you.

      "... wonder if I could add the 'scroll' feature ..."

      Tk::Scrolled explains how to do that.

      It sounds like your application is very similar (at least in terms of GUI layout) to one I wrote quite a few years ago and which I run (without any problems) fairly regularly. I put the entire Tk::NoteBook in a scrolled Tk::Pane.

      Here's a severely cutdown version of just the relevant code:

      my $mw = MainWindow->new(); ... build_main_pane(\$mw); ... sub build_main_pane { my $mw = ${+shift}; my $mp = $mw->Scrolled(q{Pane}, -scrollbars => q{osoe}, -sticky => q{nsew}, ); $mp->pack(-fill => q{both}, -expand => 1); build_notebook($mp); return; } sub build_notebook { my ($parent) = @_; my $nb = $parent->NoteBook(); $nb->pack(-fill => q{both}, -expand => 1); build_pages($nb); return; } sub build_pages { my ($nb) = @_; build_example_page($nb); build_other_page($nb); ... build_last_page($nb); return; } sub build_example_page { my ($nb) = @_; my $example_page = $nb->add(example_page => -label => 'Example Page', ... ); ... }

      -- Ken

        Thanks a bunch Ken. This piece of code really help. I know what I should do now. I'm applying your sample code in my script. Big thanks! :)

      Tips Re: Tk::Notebook - Scrolling Tabs (diy)

      Example

      #!/usr/bin/perl -- use strict; use warnings; use Tk; Main( @ARGV ); exit( 0 ); sub Main { my $mw = tkinit(); my $nb = $mw->NoteBook( -backpagecolor => 'red',)->pack(qw/-expand + 1 -fill both /); Colors($nb); $mw->geometry("200x200+200+200"); ## $mw->WidgetDump; $mw->MainLoop; } sub Colors { my( $nb ) = @_; my @color = qw[ pink maroon green OliveDrab4 PaleVioletRed3 RosyBr +own2 PeachPuff4 WhiteSmoke azure3 chartreuse1 coral3 gold1 firebrick4 + linen salmon4 tomato2 ]; for my $red( @color ){ my $frame = $nb->add( $red, -label => $red, ); my $emraf = $frame->Scrolled('Pane', -background => $red)->pac +k(qw/ -expand 1 -fill both /); $emraf->Button( -text => $_, )->pack( -side => (qw/ left right + top bottom/)[rand 4] ) for @color; } }

        Thank you Anonymous Monk, your sample codes helps me to understand on the concept. Appreciate!