Movatterモバイル変換


[0]ホーム

URL:


Tcl8.6.17/Tk8.6.17 Documentation>Tk Commands, version 8.6.17> grid

Tcl/Tk Applications |Tcl Commands |Tk Commands |[incr Tcl] Package Commands |SQLite3 Package Commands |TDBC Package Commands |tdbc::mysql Package Commands |tdbc::odbc Package Commands |tdbc::postgres Package Commands |tdbc::sqlite3 Package Commands |Thread Package Commands |Tcl C API |Tk C API |[incr Tcl] Package C API |TDBC Package C API

NAME
grid — Geometry manager that arranges widgets in a grid
SYNOPSIS
DESCRIPTION
gridwindow?window ...? ?options?
grid anchorwindow ?anchor?
grid bboxwindow ?column row? ?column2 row2?
grid columnconfigurewindow index?-option value...?
grid configurewindow?window ...? ?options?
-columnn
-columnspann
-incontainer
-ipadxamount
-ipadyamount
-padxamount
-padyamount
-rown
-rowspann
-stickystyle
grid forgetwindow?window ...?
grid infowindow
grid locationwindow x y
grid propagatewindow ?boolean?
grid rowconfigurewindow index?-option value...?
grid removewindow?window ...?
grid sizecontainer
grid slaveswindow ?-option value?
grid contentwindow ?-option value?
RELATIVE PLACEMENT
-
x
^
THE GRID ALGORITHM
GEOMETRY PROPAGATION
RESTRICTIONS ON CONTAINER WINDOWS
STACKING ORDER
CREDITS
EXAMPLES
SEE ALSO
KEYWORDS

NAME

grid — Geometry manager that arranges widgets in a grid

SYNOPSIS

gridoption arg?arg ...?

DESCRIPTION

Thegrid command is used to communicate with the gridgeometry manager that arranges widgets in rows and columns insideof another window, called the geometry container (or container window).Thegrid command can have any of several forms, dependingon theoption argument:

gridwindow?window ...? ?options?
If the first argument togrid is suitable as the first windowargument togrid configure, either a window name (any valuestarting with.) or one of the charactersx or^(see theRELATIVE PLACEMENT section below), then the command isprocessed in the same way asgrid configure.

grid anchorwindow ?anchor?
The anchor value controls how to place the grid within the container windowwhen no row/column has any weight. SeeTHE GRID ALGORITHM belowfor further details. The defaultanchor isnw.

grid bboxwindow ?column row? ?column2 row2?
With no arguments,the bounding box (in pixels) of the grid is returned.The return value consists of 4 integers. The first two are the pixeloffset from the container window (x then y) of the top-left corner of thegrid, and the second two integers are the width and height of the grid,also in pixels. If a singlecolumn androw is specified onthe command line, then the bounding box for that cell is returned, where thetop left cell is numbered from zero. If bothcolumn androwarguments are specified, then the bounding box spanning the rows and columnsindicated is returned.

grid columnconfigurewindow index?-option value...?
Query or set the column properties of theindex column of thegeometry container,window.The valid options are-minsize,-weight,-uniformand-pad.If one or more options are provided, thenindex may be given asa list of column indices to which the configuration options will operate on.Indices may be integers, window names or the keywordall. Forallthe options apply to all columns currently occupied be content windows. Fora window name, that window must be a content of this container and the optionsapply to all columns currently occupied be the content.The-minsize option sets the minimum size, in screen units,that will be permitted for this column.The-weight option (an integer value)sets the relative weight for apportioningany extra spaces amongcolumns.A weight of zero (0) indicates the column will not deviate from its requestedsize. A column whose weight is two will grow at twice the rate as a columnof weight one when extra space is allocated to the layout.The-uniform option, when a non-empty value is supplied, placesthe column in auniform group with other columns that have thesame value for-uniform. The space for columns belonging to auniform group is allocated so that their sizes are always in strictproportion to their-weight values. SeeTHE GRID ALGORITHM below for further details.The-pad option specifies the number of screen units that will beadded to the largest window contained completely in that column when thegrid geometry manager requests a size from the containing window.If only an option is specified, with no value,the current value of that option is returned.If only the container window and index is specified, all the current settingsare returned in a list of“-option value”pairs.

grid configurewindow?window ...? ?options?
The arguments consist of the names of one or more content windowsfollowed by pairs of arguments that specify howto manage the content.The characters-,x and^,can be specified instead of a window name to alter the defaultlocation of awindow, as described in theRELATIVE PLACEMENTsection, below.The following options are supported:

-columnn
Insert the window so that it occupies thenth column in the grid.Column numbers start with 0. If this option is not supplied, then thewindow is arranged just to the right of previous window specified on thiscall togrid, or column“0”if it is the first window. For eachx that immediately precedes thewindow, the column positionis incremented by one. Thus thex represents a blank columnfor this row in the grid.

-columnspann
Insert the window so that it occupiesn columns in the grid.The default is one column, unless the window name is followed by a-, in which case the columnspan is incremented once for each immediatelyfollowing-.

-incontainer
Insert the window(s) in the containerwindow given bycontainer. The default is the first window'sparent window.

-ipadxamount
Theamount specifies how much horizontal internal padding toleave on each side of the content. This is space is addedinside the content border.Theamount must be a valid screen distance, such as2 or.5c.It defaults to 0.

-ipadyamount
Theamount specifies how much vertical internal padding toleave on the top and bottom of the content.This space is added inside the content border.Theamount defaults to 0.

-padxamount
Theamount specifies how much horizontal external padding toleave on each side of the content, in screen units.Amount may be a listof two values to specify padding for left and right separately.Theamount defaults to 0.This space is added outside the content border.

-padyamount
Theamount specifies how much vertical external padding toleave on the top and bottom of the content, in screen units.Amount may be a listof two values to specify padding for top and bottom separately.Theamount defaults to 0.This space is added outside the content border.

-rown
Insert the content so that it occupies thenth row in the grid.Row numbers start with 0. If this option is not supplied, then thecontent is arranged on the same row as the previous content specified on thiscall togrid, or the next row after the highest occupied rowif this is the first content.

-rowspann
Insert the content so that it occupiesn rows in the grid.The default is one row. If the nextgrid command contains^ characters instead ofcontent that line up with the columnsof thiscontent, then therowspan of thiscontent isextended by one.

-stickystyle
If a content's cell is larger than its requested dimensions, thisoption may be used to position (or stretch) the content within its cell.Style is a string that contains zero or more of the charactersn,s,e orw.The string can optionally contains spaces orcommas, but they are ignored. Each letter refers to a side (north, south,east, or west) that the content will“stick”to. If bothn ands (ore andw) arespecified, the content will be stretched to fill the entireheight (or width) of its cavity. The-sticky option subsumes thecombination of-anchor and-fill that is used bypack.The default is“”,which causes the content to be centered in its cavity, at its requested size.

If any of the content is already managed by the geometry managerthen any unspecified options for them retain their previous values ratherthan receiving default values.

grid forgetwindow?window ...?
Removes each of thewindows from grid for itscontainer and unmaps their windows.The content will no longer be managed by the grid geometry manager.The configuration options for that window are forgotten, so that if thewindow is managed once more by the grid geometry manager, the initialdefault settings are used.

grid infowindow
Returns a list whose elements are the current configuration state ofthe content given bywindow in the same option-value form thatmight be specified togrid configure.The first two elements of the list are“-incontainer”wherecontainer is the windows's container window.

grid locationwindow x y
Givenx andy values in screen units relative to the container window,the column and row number at thatx andy location is returned.For locations that are above or to the left of the grid,-1 isreturned.

grid propagatewindow ?boolean?
Ifboolean has a true boolean value such as1 oronthen propagation is enabled forwindow, which must be a windowname (seeGEOMETRY PROPAGATION below).Ifboolean has a false boolean value then propagation isdisabled forwindow.In either of these cases an empty string is returned.Ifboolean is omitted then the command returns0 or1 to indicate whether propagation is currently enabledforwindow.Propagation is enabled by default.

grid rowconfigurewindow index?-option value...?
Query or set the row properties of theindex row of thegeometry window,window.The valid options are-minsize,-weight,-uniformand-pad.If one or more options are provided, thenindex may be given asa list of row indices to which the configuration options will operate on.Indices may be integers, window names or the keywordall. Forallthe options apply to all rows currently occupied by content windows. Fora window name, that window must be a content window of this container and the optionsapply to all rows currently occupied by the container window.The-minsize option sets the minimum size, in screen units,that will be permitted for this row.The-weight option (an integer value)sets the relative weight for apportioningany extra spaces amongrows.A weight of zero (0) indicates the row will not deviate from its requestedsize. A row whose weight is two will grow at twice the rate as a rowof weight one when extra space is allocated to the layout.The-uniform option, when a non-empty value is supplied, placesthe row in auniform group with other rows that have thesame value for-uniform. The space for rows belonging to auniform group is allocated so that their sizes are always in strictproportion to their-weight values. SeeTHE GRID ALGORITHM below for further details.The-pad option specifies the number of screen units that will beadded to the largest window contained completely in that row when thegrid geometry manager requests a size from the containing window.If only an option is specified, with no value,the current value of that option is returned.If only the container window and index is specified, all the current settingsare returned in a list of“-option value”pairs.

grid removewindow?window ...?
Removes each of thewindows from grid for itscontainer and unmaps their windows.The content will no longer be managed by the grid geometry manager.However, the configuration options for that window are remembered,so that if the content window is managed once more by the gridgeometry manager, the previous values are retained.

grid sizecontainer
Returns the size of the grid (in columns then rows) forcontainer.The size is determined either by thecontent occupying the largestrow or column, or the largest column or row with a-minsize,-weight, or-pad that is non-zero.

grid slaveswindow ?-option value?
If no options are supplied, a list of all of the content inwindoware returned, most recently managed first.Option can be either-row or-column whichcauses only the content in the row (or column) specified byvalueto be returned.

grid contentwindow ?-option value?
Synonym forgrid slaveswindow ?-option value?.

RELATIVE PLACEMENT

Thegrid command contains a limited set of capabilities thatpermit layouts to be created without specifying the row and columninformation for each content. This permits content to be rearranged,added, or removed without the need to explicitly specify row andcolumn information.When no column or row information is specified for acontent,default values are chosen for-column,-row,-columnspan and-rowspanat the time thecontent is managed. The values are chosenbased upon the current layout of the grid, the position of thecontentrelative to othercontents in the same grid command, and the presenceof the characters-,x, and^ ingridcommand wherecontent names are normally expected.

-
This increases the-columnspan of thecontent to the left. Several-'s in a row will successively increase the number of columns spanned. A-may not follow a^ or ax, nor may it be the firstcontentargument togrid configure.

x
This leaves an empty column between thecontent on the left andthecontent on the right.

^
This extends the-rowspan of thecontent above the^'sin the grid. The number of^'s in a row must match the number ofcolumns spanned by thecontent above it.

THE GRID ALGORITHM

The grid geometry manager lays out its content in three steps.In the first step, the minimum size needed to fit all of the contentis computed, then (if propagation is turned on), a request is madeof the container window to become that size.In the second step, the requested size is compared against the actual sizeof the container. If the sizes are different, then spaces is added to or takenaway from the layout as needed.For the final step, each content is positioned in its row(s) and column(s)based on the setting of itssticky flag.

To compute the minimum size of a layout, the grid geometry managerfirst looks at all content whose-columnspan and-rowspan values are one,and computes the nominal size of each row or column to be either theminsize for that row or column, or the sum of thepaddingplus the size of the largest content, whichever is greater. After thatthe rows or columns in each uniform group adapt to each other. Thenthe content whose row-spans or column-spans are greater than one areexamined. If a group of rows or columns need to be increased in sizein order to accommodate these content, then extra space is added to eachrow or column in the group according to itsweight. For eachgroup whose weights are all zero, the additional space is apportionedequally.

When multiple rows or columns belong to a uniform group, the spaceallocated to them is always in proportion to their weights. (A weightof zero is considered to be 1.) In other words, a row or columnconfigured with-weight 1 -uniform a will have exactly the samesize as any other row or column configured with-weight 1 -uniforma. A row or column configured with-weight 2 -uniform b willbe exactly twice as large as one that is configured with-weight 1-uniform b.

More technically, each row or column in the group will have a sizeequal tok*weight for some constantk. The constantk is chosen so that no row or column becomes smaller than itsminimum size. For example, if all rows or columns in a group have thesame weight, then each row or column will have the same size as thelargest row or column in the group.

For containers whose size is larger than the requested layout, the additionalspace is apportioned according to the row and column weights. If all ofthe weights are zero, the layout is placed within its container according totheanchor value.For containers whose size is smaller than the requested layout, space is takenaway from columns and rows according to their weights. However, once acolumn or row shrinks to its minsize, its weight is taken to be zero.If more space needs to be removed from a layout than would be permitted, aswhen all the rows or columns are at their minimum sizes, the layout isplaced and clipped according to theanchor value.

GEOMETRY PROPAGATION

The grid geometry manager normally computes how large a container must be tojust exactly meet the needs of its content, and it sets therequested width and height of the container to these dimensions.This causes geometry information to propagate up through awindow hierarchy to a top-level window so that the entiresub-tree sizes itself to fit the needs of the leaf windows.However, thegrid propagate command may be used toturn off propagation for one or more containers.If propagation is disabled then grid will not setthe requested width and height of the container window.This may be useful if, for example, you wish for a containerwindow to have a fixed size that you specify.

RESTRICTIONS ON CONTAINER WINDOWS

The container for each content must either be the content's parent(the default) or a descendant of the content's parent.This restriction is necessary to guarantee that thecontent can be placed over any part of its container that isvisible without danger of the content being clipped by its parent.In addition, all content in one call togrid must have the same container.

STACKING ORDER

If the container for a content is not its parent then you must make surethat the content is higher in the stacking order than the container.Otherwise the container will obscure the content and it will appear asif the content has not been managed correctly.The easiest way to make sure the content is higher than the container isto create the container window first: the most recently created windowwill be highest in the stacking order.

CREDITS

Thegrid command is based on ideas taken from theGridBaggeometry manager written by Doug. Stein, and theblt_table geometrymanager, written by George Howlett.

EXAMPLES

A toplevel window containing a text widget and two scrollbars:

# Make the widgetstoplevel .ttext .t.txt -wrap none -xscroll {.t.h set} -yscroll {.t.v set}scrollbar .t.v -orient vertical   -command {.t.txt yview}scrollbar .t.h -orient horizontal -command {.t.txt xview}# Lay them outgrid .t.txt .t.v -sticky nsewgrid .t.h        -sticky nsew# Tell the text widget to take all the extra roomgrid rowconfigure    .t .t.txt -weight 1grid columnconfigure .t .t.txt -weight 1

Three widgets of equal width, despite their different“natural”widths:

button .b -text "Foo"entry .e -textvariable foo ; set foo "Hello World!"label .l -text "This is a fairly long piece of text"grid .b .e .l -sticky ewgrid columnconfigure . "all" -uniform allTheSame

SEE ALSO

pack,place

KEYWORDS

geometry manager,location,grid,cell,propagation,size,pack
Copyright © 1996 Sun Microsystems, Inc.

[8]ページ先頭

©2009-2026 Movatter.jp