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

I'm facing the resolution issue dealing with the window size change in my monitor. Such that some context are not view-able when I invoke the Perl/TK GUI in smaller resolution window, even I tried to stretch to expand the GUI. The items inside the GUI are not resizable follows on the window size I strecthed but instead whenever I stretch the GUI smaller, some items/buttons are covered and not to be seen. This issue is not persist whenever I open the GUI in big resolution monitor.

Could anyone tell me if Perl/Tk allows flexible window re-size or any other option that could help to resolve this? I understood that we can set a size for the geometry of our GUI, and the window will enlarged when the arranged items do not fit into that size. Question is what is the margin of the geometry size that I should use so that all text and feature in GUI can be seen properly in all type of monitor resolution? Pls help. Thank you.

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

Replies are listed 'Best First'.
Re: How to set the MainWindow agile to the context in Perl/Tk
by kcott (Archbishop) on May 15, 2015 at 22:58 UTC

    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

      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

        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; } }
Re: How to set the MainWindow agile to the context in Perl/Tk
by Anonymous Monk on May 15, 2015 at 07:49 UTC

      Thank you Anonymous Monk

      You give me ample source of sample to read through.