in reply to Re^2: How to resize mainwindow automatically
in thread How to resize mainwindow automatically
I am curious what would give you that idea? pack() is the most used (far and away) geometry manager. I see nothing in your application that would require "grid". My advice: Learn how to use pack() before trying one of the other geometry managers.
One very common problem is not using enough frames. You seem to get the idea that frames can be packed inside of other frames. This is VERY common and the right way of using pack(). In my experience things like "place(-x => 100, -y => 11);", using "fixed" x,y coordinates is a bad idea, especially with some dynamic geometry things like varying the number of widgets that will be displayed.
If you want say 2 columns, make a frame for the columns, then a frame for col 1 and col 2. Pack widgets into say the left side of the column frames (also could be right or center). In this case -padx, -pady are good things to know about as well as fill.
I have found that the most helpful thing is to draw a simple diagram on paper of what you are trying to do, showing the frames and frames within frames, etc. All windows are pretty much the same except that a mainwindow will always exist (closing mainwindow exits Tk). You can hide or iconify the main windows, but it will still "exist".
I think you have a mis-understanding of what geometry() does. This IS the minimum window size! If you do the frame packing right, the window will expand. Awhile ago, I wrote a simple program to demo to show that the main window will grow at Re: Perl Tk geometry problem. Play with that simple code and you will see that you can't make the window smaller than this geometry value. I don't know of anything like "maxsize".
If the stuff to get display won't fit on screen, then as another poster suggested, scrolled is a good method. But I don't think that you need this.
I think you are getting warnings that you aren't seeing. I echo comments about "use strict; use warnings;".
My suggestion would be to come back with some code using only the standard geometry manager (pack). Make this as simple as you can to demonstrate the problems.
It is not clear to me whether you need to change this mainwindow set of buttons dynamically during course of program execution. You could clarify that requirement. Anyway the first step is to get some stuff on the screen like you want. Get that working. Then 2nd question is how to "re-do" this window with more or fewer buttons during course of program execution.
Update: I wrote some simple code for you to get started..
#!/usr/bin/perl -w use strict; use Tk; my $Fuel_Type = "diesel"; my $mainwindow = MainWindow->new (-title => " Select Fuel Tank for $Fuel_Type Fuel "); + $mainwindow->geometry("500x300"); # Defines the Fuel Frame in the Main Window # pack options cause this frame to expand to take whole # the "row" in the "x" direction #easy way to say a "row".... # define a frame that is expanded to take the entire "x" dimension # and pack stuff left justified into that frame my $frame_fuel_stuff_1 = $mainwindow ->Frame() ->pack(-side=>'top',-fill=>'x'); # Defining the Fuel and Oil Flow Rates - Instrumentation Label my $label_1 = $frame_fuel_stuff_1->Label (-text => " Which $Fuel_Type tank are you using Q1?", -relief => 'groove', ) ->pack(-side => 'left'); my $label_2 = $frame_fuel_stuff_1->Label (-text => " Some other widget can go here ", -relief => 'groove', ) ->pack(-side => 'left'); #another "row" #make a new frame that does the same thing.... # my $frame_fuel_stuff_2 = $mainwindow ->Frame() ->pack(-side=>'top',-fill=>'x'); my $label_3 = $frame_fuel_stuff_2->Label (-text => " Which $Fuel_Type tank are you using Q2?", -relief => 'groove', ) ->pack(-side =>'left'); MainLoop();
|
|---|