table(n)
๐ table(n) โ BLT Built-In Commands ๐
๐ธ NAME ๐ธ
table โ arranges widgets in a table. Thatโs the whole gig, bestie: itโs the geometry manager that puts your widgets into a table layout so everything looks intentional. ๐
โจ SYNOPSIS โจ
okay so hereโs the full command menu, exactly as written, no cap:
table container ?widget index option value?...
table arrange container
table cget container ?item? option
table configure container ?item?... ?option value?...
table extents container item
table forget widget ?widget?...
table info container item
table locate container x y
table containers ?switch? ?arg?
table save container
table search container ?switch arg?...
๐ฆ DESCRIPTION ๐ฆ
The table command arranges widgets in a table. The alignment of widgets is determined by their row and column positions and the number of rows or columns that they span. Thatโs the tea. ๐ซ
๐ INTRODUCTION ๐
ngl, probably the most painstaking aspect of building a graphical application is getting the placement and size of the widgets just right. It usually takes many iterations to align widgets and adjust their spacing. Thatโs because managing the geometry of widgets is simply not a packing problem, but also a graphical design problem. Attributes such as alignment, symmetry, and balance are more important than minimizing the amount of space used for packing. itโs giving design queen energy. ๐
The table geometry manager arranges widgets in a table. Itโs easy to align widgets horizontally and vertically, or to create empty space to balance the arrangement of the widgets. Widgets (called slaves in the Tk parlance) are arranged inside a containing widget (called the master). Widgets are positioned at row,column locations and may span any number of rows or columns. More than one widget can occupy a single location. main character widgets sharing a cell? iconic. โจ
The placement of widget windows determines both the size and arrangement of the table. The table queries the requested size of each widget. The requested size of a widget is the natural size of the widget (before the widget is shrunk or expanded). The height of each row and the width of each column is the largest widget spanning that row or column. The size of the table is in turn the sum of the row and column sizes. This is the tableโs normal size. math but make it layout. ๐งฎ
The total number of rows and columns in a table is determined from the indices specified. The table grows dynamically as windows are added at larger indices. it literally expands for you. slay. ๐ฑ
๐ EXAMPLE ๐
The table geometry manager is created by invoking the table command.
# Create a table in the root window
table .
The window . is now the container of the table. Widgets are packed into the table and displayed within the confines of the container.
You add widgets to the table by row and column location. Row and column indices start from zero.
label .title -text "This is a title"
# Add a label to the table
table . .title 0,0
The label .title is added to the table. We can add more widgets in the same way.
button .ok -text "Ok"
button .cancel -text "Cancel"
# Add two buttons
table . .ok 1,0
table . .cancel 1,1
Two buttons .ok and .cancel are now packed into the second row of the table. They each occupy one cell of the table. By default, widgets span only a single row and column.
The first column contains two widgets, .title and .ok. By default, the widest of the two widgets will define the width of the column. However, we want .title to be centered horizontally along the top of the table. We can make .title span two columns using the configure operation.
# Make the label span both columns
table configure . .title -cspan 2
The label .title will now be centered along the top row of the table. centered and thriving. ๐ฏ
In the above example, weโve created and arranged the layout for the table by invoking the table command several times. Alternately, we could have used a single table command.
label .title -text "This is a title"
button .ok -text "Ok"
button .cancel -text "Cancel"
# Create and pack the table
table . \
.title 0,0 -cspan 2 \
.ok 1,0 \
.cancel 1,1
The table will override the requested width and height of the container so that the window fits the table exactly. This also means that any change to the size of the table will be propagated up through the Tk window hierarchy. This feature can be turned off using the configure operation again.
table configure . -propagate no
You can also set the width or height of the table to a specific value. This supersedes the calculated table size.
# Make the container 4 inches wide, 3 inches high
table configure . -reqwidth 4i -reqheight 3i
If a widget is smaller than the cell(s) it occupies, the widget will float within the extra space. By default, the widget will be centered within the space, but you can anchor the widget to any side of the cell using the -anchor configuration option.
table configure . .ok -anchor w
The -fill option expands the widget to fill the extra space either vertically or horizontally (or both).
# Make the title label fill the entire top row
table configure . .title -cspan 2 -fill x
# Each button will be as height of the 2nd row.
table configure . .ok .cancel -fill y
The width of .title will be the combined widths of both columns. Both .ok and .cancel will become as tall as the second row. theyโre filling out the fit. obsessed. ๐
The -padx and -pady options control the amount of padding around the widget. Both options take a list of one or two values.
# Pad the title by two pixels above and below.
table configure . .title -pady 2
# Pad each button 2 pixels on the left, and 4 on the right.
table configure . .ok .cancel -padx { 2 4 }
If the list has only one value, then both exterior sides (top and bottom or left and right) of the widget are padded by that amount. If the list has two elements, the first specifies padding for the top or left side and the second for the bottom or right side.
Like the container, you can also override the requested widths and heights of widgets using the -reqwidth and -reqheight options. This is especially useful with character-based widgets (such as buttons, labels, text, listbox, etc) that let you specify their size only in units of characters and lines, instead of pixels.
# Make all buttons one inch wide
table configure . .ok .cancel -reqwidth 1i
Each row and column of the table can be configured, again using the configure operation. Rows and columns are designated by Ri and Ci respectively, where i is the index of the row or column.
For example, you can set the size of a row or column.
# Make the 1st column 2 inches wide
table configure . c0 -width 2.0i
# Make the 2nd row 1/2 inch high.
table configure . r1 -height 0.5i
The new size for the row or column overrides its calculated size. If no widgets span the row or column, its height or width is zero. So you can use the -width and -height options to create empty spaces in the table.
# Create an empty row and column
table configure . r2 c2 -width 1i
The -pady option lets you add padding to the top and bottom sides of rows. The -padx option adds padding to the left and right sides of columns. Both options take a list of one or two values.
# Pad above the title by two pixels
table configure . r0 -pady { 2 0 }
# Pad each column 4 pixels on the left, and 2 on the right.
table configure . c* -padx { 2 4 }
Notice that you can configure all the rows and columns using either R* or C*. wildcard moment, we love to see it. ๐
When the container is resized, the rows and columns of the table are also resized. Only the rows or columns that contain widgets (a widget spans the row or column) grow or shrink. The -resize option indicates whether the row or column can be shrunk or stretched. If the value is shrink, the row or column can only be resized smaller. If expand, it can only be resized larger. If none, the row or column is frozen at its requested size.
# Let the 1st column get smaller, but not bigger
table configure . c0 -resize shrink
# Let the 2nd column get bigger, not smaller
table configure . c1 -resize expand
# Don't resize the first row
table configure . r0 -resize none
The following example packs a canvas, two scrollbars, and a title. The rows and columns containing the scrollbars are frozen at their requested size, so that even if the frame is resized, the scrollbars will remain the same width.
table . \
.title 0,0 -cspan 3 \
.canvas 1,1 -fill both \
.vscroll 1,2 -fill y \
.hscroll 2,1 -fill x
# Don't let the scrollbars resize
table configure . c2 r2 -resize none
# Create an empty space to balance the scrollbar
table configure . c0 -width .vscroll
Note that the value of the -width option is the name of a widget window. This indicates that the width of the column should be the same as the requested width of .vscroll. itโs matching widths, bestie. coordination. ๐
Finally, the forget operation removes widgets from the table.
# Remove the windows from the table
table forget .quit .frame
Itโs not necessary to specify the container. The table command determines the container from the widget name.
๐ OPERATIONS ๐
Okay so hereโs where the table actually does stuff, bestie. These are the operations available for the table:
table container ?widget index option value?...โ Adds the widgetwidgetto the table atindex.Indexis arow,columnposition in the table. It must be in the formrow,columnwhererowandcolumnare the respective row and column numbers, starting from zero (0,0is the upper leftmost position).Rowandcolumnmay also be numeric expressions that are recursively evaluated. If a table doesnโt exist forcontainer, one is created.Widgetis the path name of the window, that must already exist, to be arranged inside ofcontainer.Optionandvalueare described in the WIDGET OPTIONS section.table arrange containerโ Forces the table to compute its layout immediately. Normally, the table geometry manager will wait until the next idle point, before calculating the size of its rows and columns. This is useful for collecting the normal sizes of rows and columns, that are based upon the requested widget sizes. Slay, layout go brr. โจtable cget container ?item? optionโ Returns the current value of the configuration option specific toitemgiven byoption.Itemis either a row or column index, or the path name of a widget.Itemcan be in any form describe in theconfigureoperation below. If noitemargument is provided, then the configuration option is for the table itself.Optionmay be any one of the options described in the appropriate section foritem.table configure container item... ?option value?...โ Queries or modifies the configuration options specific toitem. If nooptionis specified, this command returns a list describing all of the available options foritem. If the argumentitemis omitted, then the specified configuration options are for the table itself. Otherwiseitemmust be either a row or column specification, or the path name of a widget. The following item types are available:Ciโ Specifies the column ofcontainerto be configured.Itemmust be in the formCn, whereiis the index of the column. See the COLUMN OPTIONS section.Riโ Specifies the row ofcontainerto be configured.Itemmust be in the formRi, whereiis the index of the row. See the ROW OPTIONS section.widgetโ Specifies a widget ofcontainerto be queried.Widgetis the path name of a widget packed incontainer. See the WIDGET OPTIONS section.- No argument โ Specifies that the table itself is to be queried. See the TABLE OPTIONS section for a description of the option-value pairs for the table.
The option and value pairs are specific to item. If option is specified with no value, then the command returns a list describing the one named option (this list will be identical to the corresponding sublist of the value returned if no option is specified). If one or more option-value pairs are specified, then the command modifies the given option(s) to have the given value(s); in this case the command returns the empty string. Periodt, configuration understood. ๐
table extents container indexโ Queries the location and dimensions of row and columns in the table.Indexcan be either a row or column index or a table index. Returns a list of thex,ycoordinates (upperleft corner) and dimensions (widthandheight) of the cell, row, or column. Vibe check: located. โจtable forget widget ?widget?...โ Requests thatwidgetno longer have its geometry managed.Widgetis the pathname of the window currently managed by some table. The window will be unmapped so that it no longer appears on the screen. Ifwidgetis not currently managed by any table, an error message is returned, otherwise the empty string.
๐ซถ Bestie, this one literally unmaps the window โ itโs gone from the screen, no cap.
table info container itemโ Returns a list of the current configuration options foritem. The list returned is exactly in the form that might be specified to thetablecommand. It can be used to save and reset table configurations.Itemmust be one of the following:Ciโ Specifies the column ofcontainerto be queried.Itemmust be in the formCn, wherenis the index of the column.Riโ Specifies the row ofcontainerto be queried.Itemmust be in the formRi, whereiis the index of the row.widgetโ Specifies a widget ofcontainerto be queried.Widgetis the path name of a widget packed incontainer.- No argument โ Specifies that the table itself is to be queried.
table locate container x yโ Returns the table index (row,column) of the cell containing the given screen coordinates. Thexandyarguments represent thexandycoordinates of the sample point to be tested. Point-and-click core. ๐ฏtable containers ?switch arg?โ Returns a list of all container windows matching a given criteria (usingswitchandarg). If noswitchandargarguments are given, the names of all container windows (only those using thetablecommand) are returned. The following are valid switches:-pattern patternโ Returns a list of pathnames of all container windows matchingpattern.-slave windowโ Returns the name of the container window of table managingwindow.Windowmust be the path name of widget. Ifwindowis not managed by any table, the empty string is returned.
table search container ?switch arg?...โ Returns the names of all the widgets incontainermatching the criteria given byswitchandarg.Containeris name of the container window associated with the table to be searched. The name of the widget is returned if any oneswitch-argcriteria matches. If noswitch-argarguments are given, the names of all widgets managed bycontainerare returned. The following switches are available:-pattern patternโ Returns the names of any names of the widgets matchingpattern.-span indexโ Returns the names of widgets that spanindex. A widget does not need to start atindexto be included.Indexmust be in the formrow,column, whererowandcolumnare valid row and column numbers.-start indexโ Returns the names of widgets that start atindex.Indexmust be in the formrow,column, whererowandcolumnare valid row and column numbers.
๐ TABLE OPTIONS ๐
To configure the table itself, you omit the item argument when invoking the configure operation.
table configure container ?option value?...
The following options are available for the table:
-padx padโ Sets how much padding to add to the left and right exteriors of the table.Padcan be a list of one or two numbers. Ifpadhas two elements, the left side of the table is padded by the first value and the right side by the second value. Ifpadhas just one value, both the left and right sides are padded evenly by the value. The default is0. Padded and pampered. ๐-pady padโ Sets how much padding to add to the top and bottom exteriors of the table.Padcan be a list of one or two numbers. Ifpadhas two elements, the area above the table is padded by the first value and the area below by the second value. Ifpadis just one number, both the top and bottom areas are padded by the value. The default is0. Top and bottom getting their moment too. โจ-propagate booleanโ Indicates if the table should override the requested width and height of the container window. Ifbooleanis false,containerwill not be resized.Containerwill be its requested size. The default is1. Main characterbooleanenergy. ๐
๐ WIDGET OPTIONS ๐
ok so bestie, widgets get configured by naming the widget when you call the configure operation. like this:
table configure container widget ?option value?...
and widget has to be the path name of a window that's already packed in the table associated with container โ no sneaking randos in, it's gotta be an actual member of the table ๐
here's the whole menu of options for widgets:
-anchoranchor โ pins widget to a specific edge of the cell(s) it lives in. heads up: this only does anything if the space of the spans around widget is bigger than widget itself. anchor says how the widget gets positioned in that space. example: if anchor iscenterthe window is centered in the rows and columns it spans; if anchor iswthe window lines up with the leftmost edge of the span. default iscenter.-columnspannumber โ how many columns widget spans. default is1.-columncontrolcontrol โ says how widget's width should control the width of the columns it spans. control is eithernormal,none, orfull. default isnormal.noneโ the width of widget is not considered at all.fullโ only the width of widget gets considered when computing the widths of the columns. main character energy only โจnormalโ the widest widget spanning the column decides the width of the span.
-fillfill โ whether widget should stretch to fill any free space in the span around it. fill is eithernone,x,y,both. default isnone.xโ widget can grow horizontally.yโ widget can grow vertically.bothโ widget can grow both vertically and horizontally.noneโ widget does not grow along with the span.
-ipadxpixels โ how much horizontal padding gets added internally, on the left and right sides of widget. pixels has to be a valid screen distance like2or0.3i. default is0.-ipadypixels โ how much vertical padding gets added internally, on the top and bottom of widget. pixels has to be a valid screen distance like2or0.3i. default is0.-padxpad โ how much padding to add to the left and right exteriors of widget. pad can be a list of one or two numbers. if pad has two elements, the left side of widget gets padded by the first value and the right side by the second. if pad has just one value, both left and right get padded evenly by it. default is0.-padypad โ how much padding to add to the top and bottom exteriors of widget. pad can be a list of one or two numbers. if pad has two elements, the area above widget gets padded by the first value and the area below by the second. if pad is just one number, both top and bottom get padded by it. default is0.-reqheightheight โ sets the limits of the requested height for widget. height is a list of bounding values โ go peek at the BOUNDING SIZES section for what that list means. by default the height of widget is its requested height plus its internal padding (see the-ipadyoption). the bounds in height either completely override the height, or bound it between two sizes. default is"".-reqwidthwidth โ sets the limits of the requested width for widget. width is a list of bounding values โ again, BOUNDING SIZES has the deets. by default the width of widget is its requested width plus its internal padding (set the-ipadxoption). the bounds in width either completely override the width, or bound the height between two sizes. default is"".-rowspannumber โ how many rows widget spans. default is1.-rowcontrolcontrol โ says how widget's height should control the height of the rows it spans. control is eithernormal,none, orfull. default isnormal.noneโ the height of widget is not considered.fullโ only the height of widget gets considered when computing the heights of the rows.normalโ the tallest widget spanning the row decides the height of the span.
๐ธ COLUMN OPTIONS ๐ธ
to configure a column, you point at it with the column index written as Ci, where i is the index of the column you're configuring. like so:
table configure container Ci ?option value?...
and plot twist โ if you write the index as C*, then all the columns of the table get configured at once. slay, bulk edit ๐ซถ
here's what's on the menu for columns:
-padxpad โ sets the padding to the left and right of the column. pad can be a list of one or two numbers. two elements? the left side of the column gets the first value, the right side gets the second. just one value? both sides get padded evenly by it. default is0.-resizemode โ says the column can expand or shrink from its requested width when the table gets resized. mode must be one of:none,expand,shrink, orboth. if mode isexpand, the column's width grows when there's extra space in the container window. if mode isshrink, its width may get reduced past its requested width when there isn't enough space in the container. default isnone.-widthwidth โ sets the limits within which the column's width may expand or shrink. width is a list of bounding values โ the BOUNDING SIZES section explains the whole list situation. by default there are no constraints (live ur truth, column ๐).
๐ฆ ROW OPTIONS ๐ฆ
same deal but for rows, bestie. you point at a row with the row index written as Ri, where i is the index of the row:
table configure container Ri ?option value?...
and if you write the index as R*, all the rows get configured. iconic โจ
here's what rows can do:
-heightheight โ sets the limits of the height that the row may expand or shrink to. height is a list of bounding values โ see the BOUNDING SIZES section. by default there are no constraints.-padypad โ sets the padding above and below the row. pad can be a list of one or two numbers. two elements? the area above the row gets the first value and the area below gets the second. just one number? both top and bottom get padded by it. default is0.-resizemode โ says the row can expand or shrink from its requested height when the table is resized. mode must be one of:none,expand,shrink, orboth. if mode isexpand, the row's height grows when there's extra space in the container. if mode isshrink, its height may get reduced past its requested height when there isn't enough space in the container. default isnone.
๐ BOUNDING SIZES ๐
ngl, sometimes it's way more useful to limit resizes to an acceptable range than to fix the size to one exact value or ban resizing entirely. it's basically the same vibe as how the wm command lets you set a minsize and maxsize for a toplevel window โ except here you can bound the sizes that the container, a widget, a row, or a column is allowed to take. ๐ฅ
the -width, -height, -reqwidth, and -reqheight options all take a list of one, two, or three values.
let's take a previous example and, instead of preventing resizing, bound the size of the scrollbars between two values:
table . \
.title 0,0 -cspan 3 \
.canvas 1,1 -fill both \
.vscroll 1,2 -fill y \
.hscroll 2,1 -fill x
# Bound the scrollbars between 1/8 and 1/2 inch
table configure . c2 -width { 0.125 0.5 }
table configure . r2 -height { 0.125 0.5 }
table configure . vscroll .hscroll -fill both
so the scrollbars will never get smaller than 1/8 of an inch, and never get bigger than 1/2 inch. their initial size will be their requested size, as long as that requested size falls inside the bounds you set. ๐
how the elements of the list get interpreted depends on how many elements are in it:
{}โ empty list, so no bounds are set and the default sizing is performed.{ x }โ fixes the size tox. the window or partition cannot grow or shrink. periodt.{ min max }โ sets up minimum and maximum limits for the size of the window or partition. it can't be reduced less than min, and it can't be stretched beyond max.{ min max nom }โ sets the minimum and maximum size limits, plus a nominal sizenom. this overrides the calculated size of the window or partition. we love a manual override ๐
๐ MISCELLANEOUS ๐
one more lil feature that's honestly so cute: you can put two widgets in the same cell of the table. super handy when you wanna slap decorations around a widget ๐
frame .frame -bd 1 -relief sunken
button .quit -text "Quit"
# Put both the frame and the button in the same cell.
table . \
.quit 1,0 -padx 2 -pady 2 \
.frame 1,0 -fill both
๐ LIMITATIONS ๐
Okay bestie, gather round: thereโs a long-standing bug in Tk, and itโs been around since circa 1993. The tea is that there is no way to detect if a window is already a container of a different geometry manager. And yeah, this usually happens by accident โ not me calling anyone out โ like this little chaotic trio, where all three widgets are arranged in the same container ".", but each one is using a different geometry manager:
table .f1
...
pack .f2
...
grid .f3
That combo gives you bizarre window resizing, because each geometry manager is out here applying its own brand of layout policies. No cap. And when the container is a top level window (such as "."), your window manager may literally become locked, because itโs responding to a never-ending stream of resize requests. ๐ Like itโs trapped in a group chat that never stops typing.
๐ KEYWORDS ๐
framegeometry managerlocationtablesize
Okurrr, thatโs the whole manual page, bestie! ๐ Footer check: source/version is BLT 2.5, page is table(n) โ and the date field is not there in this footer, so Iโm not gonna invent one. ๐ซถโจ
๐ฆ where this page comes from
- nixpkgs unstable: blt 2.5.3
- Copyright 1991-1997 by Bell Labs Innovations for Lucent Technologies
- ๐ girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms