place() - Geometry manager for fixed or rubber-sheet placement

SYNOPSIS

instance.place([**options])

DESCRIPTION

The placer is a geometry manager for Tkinter. It provides simple fixed placement of windows, where you specify the exact size and location of one window, called the child, within another window, called the parent. The placer also provides rubber-sheet placement, where you specify the size and location of the child in terms of the dimensions of the parent, so that the child changes size and location in response to changes in the size of the parent. Lastly, the placer allows you to mix these styles of placement so that, for example, the child has a fixed width and height but is centered inside the parent.

window.place_configure([**options])
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 an empty string.
The following option-value pairs are supported:
  • anchor="where"
    "Where" specifies which point of window is to be positioned at the (x,y) location selected by the x, y, relx, and rely options. The anchor point is in terms of the outer area of including its border, if any. Thus if where is "se" then the lower-right corner of window's border will appear at the given (x,y) location in the master. The anchor position defaults to "nw".

  • bordermode="mode"
    "mode" determines the degree to which borders within the parent are used in determining the placement of the child. The default and most common value is "inside". In this case the placer considers the area of the parent to be the innermost area of the parent, inside any border: an option of x=0 corresponds to an x-coordinate just inside the border and an option of relwidth=1.0 means window will fill the area inside the master's border.
    If "mode" is "outside" then the placer considers the area of the parent to include its border; this mode is typically used when placing window outside its parent, as with the options x=0 ,y=0 ,anchor="ne". Lastly, "mode" may be specified as "ignore", in which case borders are ignored: the area of the parent is considered to be its official X area, which includes any internal border but no external border. A bordermode of "ignore" is probably not very useful.

  • height=size
    Size specifies the height for window in screen units (i.e. any of the forms accepted by Screen Units). The height will be the outer dimension of window including its border, if any. If no height or relheight option is specified, then the height requested internally by the window will be used.

  • relheight=size
    Size specifies the height for window. In this case the height is specified as a floating-point number relative to the height of the parent: 0.5 means window will be half as high as the parent, 1.0 means window will have the same height as the parent, and so on. If both height and relheight are specified for a child, their values are summed. For example, relheight=1.0 ,height=-2 makes the child 2 pixels shorter than the parent.

  • relwidth=size
    Size specifies the width for window. In this case the width is specified as a floating-point number relative to the width of the parent: 0.5 means window will be half as wide as the parent, 1.0 means window will have the same width as the parent, and so on. If both width and relwidth are specified for a child, their values are summed. For example, relwidth=1.0 ,width=5 makes the child 5 pixels wider than the parent.

  • relx=location
    Location specifies the x-coordinate within the parent window of the anchor point for window. In this case the location is specified in a relative fashion as a floating-point number: 0.0 corresponds to the left edge of the parent and 1.0 corresponds to the right edge of the parent. Location need not be in the range 0.0-1.0. If both x and relx are specified for a child then their values are summed. For example, relx=0.5 ,x=-2 positions the left edge of the slave 2 pixels to the left of the center of its parent.

  • rely=location
    Location specifies the y-coordinate within the parent window of the anchor point for window. In this case the value is specified in a relative fashion as a floating-point number: 0.0 corresponds to the top edge of the parent and 1.0 corresponds to the bottom edge of the parent. Location need not be in the range 0.0-1.0. If both y and rely are specified for a child then their values are summed. For example, rely=0.5 ,x=3 positions the top edge of the child 3 pixels below the center of its parent.

  • width=size
    Size specifies the width for window in screen units (i.e. any of the forms accepted by Screen Units). The width will be the outer width of window including its border, if any. If size is an empty string, or if no width or relwidth option is specified, then the width requested internally by the window will be used.

  • x=location
    Location specifies the x-coordinate within the parent window of the anchor point for window. The location is specified in screen units (i.e. any of the forms accepted by Screen Units) and need not lie within the bounds of the parent window.

  • y=location
    Location specifies the y-coordinate within the parent window of the anchor point for window. The location is specified in screen units (i.e. any of the forms accepted by Screen Units) and need not lie within the bounds of the parent window.
If the same value is specified separately with two different options, such as x and relx, then the most recent option is used and the older one is ignored.

window.place_forget()
Causes the placer to stop managing the geometry of window. As a side effect of this method window will be unmapped so that it does not appear on the screen. If window is not currently managed by the placer then the command has no effect. This method returns an empty string.

window.place_info()
Returns a list giving the current configuration of window. The list consists of option-value pairs in the form: {'in': master, 'x': 'location', 'relx': 'location', 'y': 'location', 'rely': 'location', 'width': 'size', 'relwidth': 'size', 'height': 'size', 'relheight': 'size', 'anchor': 'where', 'bordermode': 'mode'}

window.place_slaves()
Returns a list of all the child windows for which window is the parent. If there are no childs for window then an empty list is returned.

EXAMPLE

Make the label occupy the middle bit of the toplevel, no matter how it is resized:

import tkinter

root = tkinter.Tk()

l = tkinter.Label(root ,text="In the\nMiddle!" ,bg="black" ,fg="white")
l.place(relwidth=.3 ,relx=.35 ,relheight=.3 ,rely=.35)

root.mainloop()

Comments