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
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |