The data-entry form style of layout works very well with the
grid command, since placing widgets into columns
and rows is exactly what you want to do for data-entry forms.
Typically, you'll use label and entry widgets
throughout the form. The entry widgets accept the data,
the label widgets explain the purpose of the entry.
The problem with most layouts is that you often need differing
text lengths and differing entry widths. Together, this means
that nice rows and columns get messed up.
With the grid layout, though, you simply place widgets into columns
and rows and the grid layout manager ensures that the columns and
rows line up.
The short example below shows four columns of widgets: labels,
entries, labels and entries, for a a hypothetical computer user database.
When you run the code below, you'll see a window a lot like the following.
Note how even though some labels have more text than others, everything
still lines up. Also, to make all the labels aligned to the right side,
I used only "East" (or e) stickiness in the grid configurations
for the label widgets.
#
# grid2.tcl
# Test of new grid packing command.
# This test shows how to make a data entry form.
#
# 21-Feb-96
# Copyright 1996 Eric Foster-Johnson
#
# In this example, we have two columns of data entry
# fields. Under the hood, we use four columns because
# the labels take up one column and the data-entry
# fields take up another column.
#
# Labels for the data entry fields.
#
# Note that a few of the labels use a lot of text to
# show the effects of the grid layout.
#
label .l_name -text "Full name: "
label .l_titlw -text "Title: "
label .l_addr -text "Address: "
label .l_offph -text "Office phone number: "
label .l_faxph -text "Fax: "
label .l_user -text "User name: "
label .l_homesys -text "Home system name: "
label .l_email -text "Email: "
label .l_url -text "URL: "
# Data-entry fields. Note the different lengths to
# show the effect of the grid.
entry .e_name -width 20
entry .e_titlw -width 10
entry .e_addr -width 20
entry .e_offph -width 10
entry .e_faxph -width 10
entry .e_user -width 12
entry .e_homesys -width 12
entry .e_email -width 20
entry .e_url -width 20
# Set up grid layout (instead of packing).
grid config .l_name -column 0 -row 0 -sticky "e"
grid config .l_titlw -column 0 -row 1 -sticky "e"
grid config .l_addr -column 0 -row 2 -sticky "e"
grid config .l_offph -column 0 -row 3 -sticky "e"
grid config .l_faxph -column 0 -row 4 -sticky "e"
grid config .e_name -column 1 -row 0 -sticky "snew"
grid config .e_titlw -column 1 -row 1 -sticky "snew"
grid config .e_addr -column 1 -row 2 -sticky "snew"
grid config .e_offph -column 1 -row 3 -sticky "snew"
grid config .e_faxph -column 1 -row 4 -sticky "snew"
grid config .l_user -column 2 -row 0 -sticky "e"
grid config .l_homesys -column 2 -row 1 -sticky "e"
grid config .l_email -column 2 -row 2 -sticky "e"
grid config .l_url -column 2 -row 3 -sticky "e"
grid config .e_user -column 3 -row 0 -sticky "snew"
grid config .e_homesys -column 3 -row 1 -sticky "snew"
grid config .e_email -column 3 -row 2 -sticky "snew"
grid config .e_url -column 3 -row 3 -sticky "snew"
#
# Set up grid for resizing.
#
grid columnconfigure . 1 -weight 1
grid columnconfigure . 3 -weight 1
|