Ulysses
Ulysses

Reputation: 6015

Tcl/Tk: How to auto expand frame to fill a row in grid

I am trying to create a tk window which has two frames. First on top and another below. The Frame on top should contain a text box which needs to fill out the entire frame.

But using the code below, I found that the frame is only half filling the window and the text box is only half filling the frame. I am using the grid approach so that it auto expands but neither did it not auto expand nor did the widgets fill out their respective containers. I am wodnering if the grid approch correct for this purpose?

namespace eval RESTLogVwr {}
toplevel .t
wm geometry .t 1500x800+10+10
wm resizable .t 0 0
grid rowconfigure .t 2 -weight 1
frame .t.f1 -bd 2 -relief groove -bg blue
text .t.f1.text -state disabled -bg black
pack .t.f1.text -fill both -expand 0
grid config .t.f1 -row 2 -column 3 -columnspan 1 -rowspan 1  -sticky "snew"
grid config .t.f1.text -row 2 -column 3 -columnspan 1 -rowspan 1  -sticky "snew"
grid rowconfigure .t 2 -weight 1

Upvotes: 1

Views: 2704

Answers (2)

Peter Lewerin
Peter Lewerin

Reputation: 13252

toplevel .t
wm geometry .t 1500x800+10+10
wm resizable .t 0 0
frame .t.f1 -bd 2 -relief groove -bg blue
text .t.f1.text -state disabled -bg black
pack .t.f1.text -fill both -expand 0

Here .t.f1.text is already managed by pack: you don’t need to manage it by grid.

grid .t.f1 -row 2 -column 3 -sticky snew
grid rowconfigure .t .t.f1 -weight 1
grid columnconfigure .t .t.f1 -weight 1

By setting weight for both column and row, you enable the frame to expand in both dimensions.

Documentation: frame (widget), grid, pack, text (widget), toplevel, wm

Upvotes: 3

Donal Fellows
Donal Fellows

Reputation: 137587

The problem is that you've asked the row containing frame .t.f1 to expand, but haven't asked the row containing text .t.f1.text to expand. (The -sticky option describes how the widgets expand to the space they've been given, but not not how much space to give the cell containing the widget in the first place.)

I'm guessing that the problem is that you say:

grid rowconfigure .t 2 -weight 1

twice, which is redundant and an indication that you've got the configuration wrong; change the second one (at the end of your sample script) to this to fix things:

grid rowconfigure .t.f1 2 -weight 1

General point: I find it helps to keep grids as shallow as possible when designing things, and to draw out (on paper if necessary) where the cell boundaries are supposed to be. Each level needs its own designing, and only very complicated designs (where I'd want to just not use the complexity at all) need extra frames.

Upvotes: 1

Related Questions