Reputation: 573
I created a grid that contains five labels each label in a row but I want in each row has the same size of previous label least size of one colone
code :
label .f0 -text "frame 0"\
-relief groove \
-borderwidth 2 \
-background blue
label .f1 -text "frame 1" \
-relief groove \
-borderwidth 2 \
-background gray
label .f2 -text "frame 2" \
-relief groove \
-borderwidth 2 \
-background green
label .f3 -text "frame 3" \
-relief groove \
-borderwidth 2 \
-background yellow
label .f4 -text "frame 4"\
-relief groove \
-borderwidth 2 \
-background red
grid .f0 -row 1 -column 1 -sticky ewns
grid .f1 -row 2 -column 2 -sticky ewns
grid .f2 -row 3 -column 3 -sticky ewns
grid .f3 -row 4 -column 4 -sticky ew
grid .f4 -row 5 -column 5 -sticky ew
printScr :
So my question is how I can filling the space that the arrow indicates with Grid not pack
Upvotes: 0
Views: 105
Reputation: 5723
You can use the -columnspan option to grid to specify how many columns to use:
grid .f0 -row 1 -column 1 -sticky ewns -columnspan 5
References: grid
Edit:
foreach i {0 1 2 3 4} {
grid columnconfigure . $i -weight 1 -uniform labcol
grid .f$i -column $i -sticky ew -columnspan [expr {5-$i}]
}
This is similar to Peter's setting of minsize. It makes all the columns the same width.
Upvotes: 2
Reputation: 13252
(2nd try) Add this after your code as in the question:
foreach index {1 2 3 4 5} {
grid columnconfigure . $index -minsize [winfo width .f0]
}
grid configure .f0 -columnspan 5
grid configure .f1 -columnspan 4
grid configure .f2 -columnspan 3
grid configure .f3 -columnspan 2
Documentation: foreach, grid, winfo
Upvotes: 1