Your problem is not within this code at all. It is most likely with how you are placing the widgets within this window. Note: in your code, width and height are the minimum main window size. It will get bigger if needed (even without resizeable). Resizeable means that the user can manually re-size the window.

The key thing is that you need to learn about Frames! A frame is a "non-visible" rectangle that is used to control screen placement with the pack geometry manager. You should always put widgets inside of frames. Pack is the most common manager and normally should be used instead of grid.

run the below code and play... What this does is start the main window at a ridiculously small width value of "50". Then a frame is drawn inside of it. Then some buttons are "packed" in that frame. The "packing" says that all of these buttons are essentially on "one line" - ie consecutive things starting at left border of frame. This causes the width of the main window to increase so that all buttons are visible! If the buttons were just inside the main window, without the directions from the frame and pack, then they would "squish" around and do goofy things as window is re-sized. I presume this is what is happening to you.

Turn on resizeable, ie. take # comment out below to play with manual resizing of the window to see what happens. You can't make the buttons "disappear" from the screen, even by resizing the window manually. There are ways to do that with "scrollable", but that isn't what you want!

The windows should re-size as needed between different screen resolutions although sometimes there are some "tricks" about that. Sometimes the mapping between screen unit and font size isn't quite perfect. On my machine the name "Windows" gets squished a bit when letting Tk "grow" the mainwindow. You can just put a Label as last button in frame with say a space or two as name to force a slightly wider Window. Although you are probably going to have some other frame wider than this "button frame" that will have the same effect.
Update: there are various "pad" things that can cause essentially similar effects for you. But without knowing more, I didn't want to get too complex im my example.

#!/usr/bin/perl -w use strict; use Tk; #only a small relevant portion is shown here my $mw = MainWindow->new; my $width = '50'; my $height = '180'; $mw->geometry( $width."x".$height); #$mw->resizable(1,1); $mw->title("Calculator"); my $menu_f = $mw->Frame()->pack(-side=>'top',-fill=>'x'); my $menu_file = $menu_f->Menubutton (-text=>'File',-tearoff=>'false') ->pack(-side=>'left'); my $menu_tools = $menu_f->Menubutton (-text=>'Tools',-tearoff=>'false') ->pack(-side=>'left'); my $menu_windows = $menu_f->Menubutton (-text=>'Windows',-tearoff=>'false') ->pack(-side=>'left'); MainLoop();

In reply to Re: Perl Tk geometry problem by Marshall
in thread Perl Tk geometry problem by lollysticky

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.