place(3pm)

πŸŽ€ place β€” Tk's geometry manager, but make it make sense πŸŽ€

okay bestie, this is the manual page for place(3pm) β€” the Tk::place module, aka the thing that decides where your widgets actually live on screen. grab a snack, we're doing this. ✨


🌸 NAME 🌸

Tk::place β€” geometry manager for fixed or rubber-sheet placement


πŸ¦‹ SYNOPSIS πŸ¦‹

$widget->place?(-option=>value?, -option=>value, ...)?

$widget->placeForget

$widget->placeInfo

$master->placeSlaves

πŸ’– DESCRIPTION πŸ’–

The placer is a geometry manager for Tk. Real talk: it's the one that does fixed placement, where you straight-up tell it the exact size and location of one window β€” called the slave β€” inside another window β€” called the master. Iconic. But wait, there's more: the placer also does rubber-sheet placement, where you describe the slave's size and location in terms of the master's dimensions, so the slave stretches and shifts whenever the master changes size. And because it's generous like that, the placer lets you mix these two styles β€” so, for example, your slave can have a fixed width and height but be centered inside the master. no cap, it's giving versatile. πŸ’…

⭐ $slave->place?(-option=>value?, -option=>value, ...?)?

This method arranges for the placer to manage the geometry of $slave. The rest of the arguments are one or more -option=>value pairs that specify how $slave's geometry gets managed. -option can be any of the values that the placeConfigure method accepts.

The place method returns $slave. 🫢

⭐ $slave->placeConfigure?(-option=>value?, -option=>value, ...?)?

Query or modify the geometry options of $slave, your choice, main character energy.

  • If no option is specified, this method returns a list describing the available options (peep Tk_ConfigureInfo for info on the format of this list).
  • If an option is specified with no value, then the command returns a list describing the one named option β€” and yes, that list will be identical to the corresponding sublist of the value you'd get back if you'd specified no option at all.
  • If one or more option-value pairs are specified, then the method modifies the given option(s) to have the given value(s); in this case the command returns "undef".

The following -option=>value pairs are supported:

  • -anchor => where β€” where specifies which point of $slave 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 $slave, including its border, if any. So if where is se, then the lower-right corner of $slave'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 master are used in figuring out the slave's placement. The default and most common value is inside. In this case the placer considers the area of the master to be the innermost area of the master, 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 $slave will fill the area inside the master's border. If mode is outside then the placer considers the area of the master to include its border; this mode is typically used when placing $slave outside its master, 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 master is considered to be its official X area, which includes any internal border but no external border. Heads up: a bordermode of ignore is probably not very useful. πŸ™ˆ
  • -height => size β€” size specifies the height for $slave in screen units (i.e. any of the forms accepted by Tk_GetPixels). The height will be the outer dimension of $slave including its border, if any. If size is an empty string, or if no -height or -relheight option is specified, then the height requested internally by the window will be used.
  • -in => $master β€” $master is the reference to the window relative to which $slave is to be placed. $master must either be $slave's parent or a descendant of $slave's parent. On top of that, $master and $slave must both be descendants of the same top-level window. These restrictions are necessary to guarantee that $slave is visible whenever $master is visible. If this option isn't specified then the master defaults to $slave's parent. πŸ‘‘
  • -relheight => size β€” size specifies the height for $slave, but this time as a floating-point number relative to the height of the master: 0.5 means $slave will be half as high as the master, 1.0 means $slave will have the same height as the master, and so on. If both -height and -relheight are specified for a slave, their values are summed. For example, -relheight=>1.0, -height=>-2 makes the slave 2 pixels shorter than the master.
  • -relwidth => size β€” size specifies the width for $slave as a floating-point number relative to the width of the master: 0.5 means $slave will be half as wide as the master, 1.0 means $slave will have the same width as the master, and so on. If both -width and -relwidth are specified for a slave, their values are summed. For example, -relwidth=>1.0, -width=>5 makes the slave 5 pixels wider than the master.
  • -relx => location β€” location specifies the x-coordinate within the master window of the anchor point for the $slave widget, in a relative fashion as a floating-point number: 0.0 corresponds to the left edge of the master and 1.0 corresponds to the right edge of the master. location does not need to be in the range 0.0-1.0. If both -x and -relx are specified for a slave 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 master.
  • -rely => location β€” location specifies the y-coordinate within the master window of the anchor point for the $slave widget, specified relatively as a floating-point number: 0.0 corresponds to the top edge of the master and 1.0 corresponds to the bottom edge of the master. location does not need to be in the range 0.0-1.0. If both -y and -rely are specified for a slave then their values are summed. For example, -rely=>0.5, -x=>3 positions the top edge of the slave 3 pixels below the center of its master.
  • -width => size β€” size specifies the width for $slave in screen units (i.e. any of the forms accepted by Tk_GetPixels). The width will be the outer width of $slave 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 master window of the anchor point for the $slave widget. The location is specified in screen units (i.e. any of the forms accepted by Tk_GetPixels) and does not need to lie within the bounds of the master window.
  • -y => location β€” location specifies the y-coordinate within the master window of the anchor point for the $slave widget. The location is specified in screen units (i.e. any of the forms accepted by Tk_GetPixels) and does not need to lie within the bounds of the master window.
⚠️ bestie listen: 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. last one wins, periodt.

⭐ $slave->placeForget

The placeForget method causes the placer to stop managing the geometry of $slave. As a side effect of this method call, $slave will be unmapped so that it doesn't appear on the screen β€” poof, gone. If $slave isn't currently managed by the placer then the method call has no effect at all. placeForget returns an empty string as its result. πŸ’€

⭐ $slave->placeInfo

The placeInfo method returns a list giving the current configuration of $slave. That list consists of -option=>value pairs in exactly the same form as might be specified to the place method. receipts, basically. 🧾

⭐ $slave->placeSlaves

The placeSlaves method returns a list of all the slave windows for which $master is the master. If there are no slaves for $master then an empty list is returned.

If the configuration of a window has been retrieved with placeInfo, that configuration can be restored later by first using placeForget to erase any existing information for the window and then invoking place with the saved information. save & restore, it's giving ctrl+z for widget placement. ✨

✨ FINE POINTS ✨

okay so plot twist incoming: the master window does not have to be the parent of the slave window. not required. it's giving freedom. and this little feature is useful in at least two situations, so let's get into it πŸ’…

First up β€” for complex window layouts, it means you can build a whole hierarchy of subwindows whose only job is to help with the layout of the parent. so the "real children" of the parent (aka the windows that actually matter for the application's user interface) can be children of the parent while still being placed inside the windows of the geometry-management hierarchy. and why do we care? because it means the path names of those "real children" don't reflect the geometry-management hierarchy at all, so users can specify options for the real children without ever being aware of the structure of the geometry-management hierarchy. clean. no notes. 🌸

Second reason for having a master that's different from the slave's parent? tying two siblings together 🫢 for example, the placer can be used to force a window to always be positioned centered just below one of its siblings by specifying this configuration:

-in=>$sibling, -relx=>0.5, -rely=>1.0, -anchor=>'n',
-bordermode=>'outside'

and whenever the $sibling widget gets repositioned in the future, the slave gets repositioned right along with it. they're bonded fr fr. πŸ”₯


⚠️ okay important one: unlike many other geometry managers (such as the packer), the placer does not make any attempt to manipulate the geometry of the master windows or the parents of slave windows β€” like, it doesn't set their requested sizes. none of that.

so if you want to control the sizes of these windows, make them windows like frames and canvases that provide configuration options for this purpose. that's the move. ✨


πŸ‘€ SEE ALSO πŸ‘€

  • Tk::form
  • Tk::grid
  • Tk::pack

πŸ”‘ KEYWORDS πŸ”‘

  • geometry manager
  • height
  • location
  • master
  • place
  • rubber sheet
  • slave
  • width

and that's the whole page bestie, you ate it πŸ’– this was place(3pm) from perl v5.40.1, dated 2025-04-13 β€” go forth and position your widgets with main character energy, no cap πŸ‘‘πŸ¦‹

πŸ“¦ where this page comes from