beetlebug▾
/

place

Puts a widget at a fixed place and size in a container, in pixels or in fractions of the container.

place WINDOW OPTION VALUE ?OPTION VALUE ...?
place SUBCOMMAND WINDOW ?ARG ...?

Description

The geometry manager place gives each widget a position and a size of its own. A position or a size is a distance in pixels, a fraction of the container, or the sum of the two. The other widgets of the container have no effect on the place of the widget, so placed widgets can be on top of each other.

A first word that starts with a dot is the same as place configure. The container is the parent of the widget, or the value of -in. place does not change the requested size of the container. A toplevel cannot be placed.

Subcommands

SubcommandDescription
place configureGives or sets the options of a placed widget.
place forgetTakes a widget out of the control of place and off the screen.
place infoGives the options of a placed widget.
place slavesGives the widgets that place puts in a container.
place contentGives the widgets that place puts in a container.

Options

OptionTypeDefaultDescription
-anchoranchornwThe point of the widget that goes at the position of -x and -y.
-bordermodeborder modeinsideWhether the border of the container is part of the space of the widget.
-heightscreen distanceemptyThe height of the widget in pixels, added to the height of -relheight.
-inwindow namethe parentThe container that the position and the size are relative to.
-relheightnumberemptyThe height of the widget as a fraction of the height of the container.
-relwidthnumberemptyThe width of the widget as a fraction of the width of the container.
-relxnumber0The x position as a fraction of the width of the container.
-relynumber0The y position as a fraction of the height of the container.
-widthscreen distanceemptyThe width of the widget in pixels, added to the width of -relwidth.
-xscreen distance0The x position in pixels, added to the position of -relx.
-yscreen distance0The y position in pixels, added to the position of -rely.

-anchor ANCHOR

The point of the widget that goes at the position of -x and -y.

nw puts the top left corner of the widget at the position. center puts the center of the widget there, and se the bottom right corner.

Values: n, ne, e, se, s, sw, w, nw, center.

% frame .an -width 100 -height 100
> pack .an
> frame .an.a -width 20 -height 10
> place .an.a -x 50 -y 50 -anchor se
> update
> list [winfo x .an.a] [winfo y .an.a]
30 40
% place .an.a -anchor middle
bad anchor "middle": must be n, ne, e, se, s, sw, w, nw, or center
-errorcode NONE

-bordermode MODE

Whether the border of the container is part of the space of the widget.

inside measures the positions and the sizes from the inner edge of the border of the container. outside and ignore measure them from the outer edge of the container.

Values: inside, outside, ignore.

% frame .bm -width 100 -height 100 -borderwidth 10
> pack .bm
> frame .bm.a -width 10 -height 10
> place .bm.a -x 0 -y 0
> update
> set r [winfo x .bm.a]
> place .bm.a -bordermode outside
> update
> lappend r [winfo x .bm.a]
10 0

% place .bm.a -relwidth 1 -bordermode inside
> update
> set r [winfo width .bm.a]
> place .bm.a -bordermode outside
> update
> lappend r [winfo width .bm.a]
80 100
% place .bm.a -bordermode bad
bad bordermode "bad": must be inside, outside, or ignore
-errorcode NONE

-height DISTANCE

The height of the widget in pixels, added to the height of -relheight.

An empty value, the default, uses the requested height of the widget when -relheight is empty too.

% frame .he -width 100 -height 100
> pack .he
> frame .he.a -width 20 -height 10
> place .he.a -height 30
> update
> winfo height .he.a
30
% place .he.a -height x
bad screen distance "x"
-errorcode NONE

-in CONTAINER

The container that the position and the size are relative to.

CONTAINER must be the parent of the widget or a descendant of that parent, and it cannot be the widget itself.

% frame .in
> frame .in.a
> frame .in.b
> place .in.b -in .in.a
> place slaves .in.a
.in.b
% frame .in2
> place .in2 -in .in2
can't place .in2 relative to itself
-errorcode NONE

% frame .in3
> frame .in4
> frame .in4.a
> place .in4.a -in .in3
can't place .in4.a relative to .in3
-errorcode NONE

-relheight FRACTION

The height of the widget as a fraction of the height of the container.

0.5 is half the height of the container, and 1 is its full height. -height adds pixels to it. An empty value uses no fraction.

% frame .rh -width 100 -height 80
> pack .rh
> frame .rh.a
> place .rh.a -relheight 0.5 -height 4
> update
> winfo height .rh.a
44
% place .rh.a -relheight x
expected floating-point number but got "x"
-errorcode NONE

-relwidth FRACTION

The width of the widget as a fraction of the width of the container.

0.5 is half the width of the container, and 1 is its full width. -width adds pixels to it. An empty value uses no fraction.

% frame .rw -width 200 -height 50
> pack .rw
> frame .rw.a
> place .rw.a -relwidth 0.5
> update
> winfo width .rw.a
100
% place .rw.a -relwidth x
expected floating-point number but got "x"
-errorcode NONE

-relx FRACTION

The x position as a fraction of the width of the container.

0 is the left edge of the container and 1 is its right edge. -x adds pixels to it. A value below 0 or above 1 puts the widget outside the container.

% frame .rx -width 200 -height 50
> pack .rx
> frame .rx.a -width 10 -height 10
> place .rx.a -relx 0.5 -x 5
> update
> winfo x .rx.a
105
% place .rx.a -relx x
expected floating-point number but got "x"
-errorcode NONE

-rely FRACTION

The y position as a fraction of the height of the container.

0 is the top edge of the container and 1 is its bottom edge. -y adds pixels to it.

% frame .ry -width 50 -height 100
> pack .ry
> frame .ry.a -width 10 -height 10
> place .ry.a -rely 0.25
> update
> winfo y .ry.a
25
% place .ry.a -rely x
expected floating-point number but got "x"
-errorcode NONE

-width DISTANCE

The width of the widget in pixels, added to the width of -relwidth.

An empty value, the default, uses the requested width of the widget when -relwidth is empty too.

% frame .wi -width 200 -height 50
> pack .wi
> frame .wi.a -width 20 -height 10
> place .wi.a -width 30 -relwidth 0.5
> update
> winfo width .wi.a
130
% place .wi.a -width x
bad screen distance "x"
-errorcode NONE

-x DISTANCE

The x position in pixels, added to the position of -relx.

The distance from the left edge of the container to the point of -anchor. A negative value is allowed.

% frame .xx -width 100 -height 50
> pack .xx
> frame .xx.a -width 10 -height 10
> place .xx.a -x 15
> update
> winfo x .xx.a
15
% place .xx.a -x x
bad screen distance "x"
-errorcode NONE

-y DISTANCE

The y position in pixels, added to the position of -rely.

The distance from the top edge of the container to the point of -anchor. A negative value is allowed.

% frame .yy -width 100 -height 50
> pack .yy
> frame .yy.a -width 10 -height 10
> place .yy.a -y 5
> update
> winfo y .yy.a
5
% place .yy.a -y z
bad screen distance "z"
-errorcode NONE

Examples

# The center of the label is at the center of the frame.
% frame .box -width 200 -height 100
> pack .box
> label .box.tag -text Hi
> place .box.tag -relx 0.5 -rely 0.5 -anchor center
> update
> list [expr {[winfo x .box.tag] + [winfo width .box.tag] / 2}] [expr {[winfo y .box.tag] + [winfo height .box.tag] / 2}]
100 50

% frame .box2 -width 50 -height 50
> pack .box2
> frame .box2.a -width 20 -height 20
> place .box2.a -x 10 -y 10
> update
> list [winfo reqwidth .box2] [winfo manager .box2.a]
50 place

Errors

% place
wrong # args: should be "place option|pathName args"
-errorcode TCL WRONGARGS

% place bogus .
bad option "bogus": must be configure, content, forget, info, or slaves
-errorcode NONE

% place .nope -x 1
bad window path name ".nope"
-errorcode NONE

% toplevel .top
> place .top -x 1
can't use placer on top-level window ".top"; use wm command instead
-errorcode NONE

Differences from Tcl

Facts

Capability
None.
Tcl release
Tcl 9.1 and 8.6.
Since
ztk 1.0.0-beta.1

See also