[Tutor] Tkinter + frame + grid question
Alan Gauld
alan.gauld at yahoo.co.uk
Mon May 15 11:08:07 EDT 2017
On 15/05/17 07:11, Phil wrote:
> I'd like to place a red frame in the centre of the main window.
What do you want surrounding it?
You are going to have to use whichever layout manager
fits the scenario. Remember you can use different layout
managers in each frame in your app - and you will usually
have several frames.
Lets assume you fill your main window with a single
frame(via pack) then use a 3x3 grid inside that frame
and put your red frame in the centre cell of your
grid.
That will give you the centre red frame plus space for
8 surrounding components or frames
> ...I did learn that grid() and pack() are not compatible
I don't know what you mean by that. You can freely mix frames
with grid/pack/place layout managers but only one manager can
be used at a time per frame. So if you adopted the scheme
above the top level window uses pack() the enclosed frame
uses grid. The red frame can use place, or pack or grid
(or any of the other layout managers available, for example,
Tix provides a Form manager)
Sketching out how your frames and components will be laid
out on paper is often a good idea. That will help you decide
how many frames you need and which layout manager to use
per frame.
I rend to use a standard layout of
MainWindow
Menubar(not allocated by layout manager0
Frame
single row grid for toolbar buttons
Frame
main grid of controls/subframes (usually
there will be 3 or 4 subframes holding
the actual components, these subframes
will usually use pack())
Frame
status bar labels
The three top level frames are packed in the mainwindow
The top frame uses pack for the buttons(but could use
a 1 row grid instead)
The centre frame tends to use Grid(but might use Form if I'm using tix)
The bottom frame will use pack (but again, could be a single row grid)
HTH
--
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos
More information about the Tutor
mailing list