Skip to content
Tutorials Center
My learning

Topics

Lesson 16 of 40 ยท Layout Managers

The Tkinter place() Layout Manager

Position Tkinter widgets exactly with place(): absolute x and y, relative relx and rely, anchor, relwidth, overlays and badges, plus when not to use place at all.

pack and grid flow widgets automatically. place does the opposite: you say exactly where each widget goes, either in pixels or as a fraction of the parent's size. It is the right tool for a small set of cases (overlays, badges, floating buttons, centered messages, simple fixed layouts) and the wrong tool for general forms, which is why it is the least used of the three.

Absolute placement

Python
import tkinter as tk

root = tk.Tk()
root.geometry("300x200")

tk.Label(root, text="Top left", bg="#e76f51").place(x=10, y=10)
tk.Label(root, text="Somewhere", bg="#2a9d8f").place(x=120, y=80, width=100, height=40)
root.mainloop()

x and y are pixel offsets of the widget's anchor point from the top-left corner of the parent. width and height set an exact size; leave them out and the widget uses its natural size. Absolute coordinates do not adapt: on a high-DPI display or a larger font the widgets can overlap or be cut off, and they do not move when the window is resized. For that, use relative coordinates.

Relative placement

relx and rely are fractions from 0.0 to 1.0 of the parent's width and height. relwidth and relheight size the widget as a fraction of the parent. They update automatically on resize.

Python
tk.Label(root, text="Centered", bg="#264653", fg="white").place(relx=0.5, rely=0.5, anchor="center")
tk.Label(root, text="Bottom right").place(relx=1.0, rely=1.0, anchor="se", x=-10, y=-10)
tk.Frame(root, bg="#e9c46a").place(relx=0, rely=0, relwidth=1.0, height=30)    # a header bar

The anchor

anchor chooses which point of the widget is placed at the computed position: "nw" (default, the top-left corner), "n", "ne", "e", "se", "s", "sw", "w" or "center". That is why relx=0.5, rely=0.5, anchor="center" centers a widget: the widget's center lands on the parent's center. Without the anchor, only its top-left corner would be at the middle.

Mixing relative and absolute

Relative and absolute values add: the final position is relx * parent_width + x. This is useful for margins: relx=1.0, x=-10, anchor="ne" puts a widget 10 pixels in from the right edge. The stand-in below implements the exact formulas so you can try combinations and predict the result.

Python Stand-in: place() coordinates

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Compare the two parent sizes: the centered and bottom-right labels move with the parent, while "x=10, y=10" stays put. Output columns are (left, top, width, height).

Common uses

A notification badge over a button's corner:

Python
badge = tk.Label(button_frame, text="3", bg="red", fg="white", font=("Arial", 8, "bold"))
badge.place(relx=1.0, rely=0.0, anchor="center")     # on the top-right corner

A loading overlay that covers the whole window and hides what is below until you remove it:

Python
overlay = tk.Frame(root, bg="#000000")
overlay.place(relx=0, rely=0, relwidth=1, relheight=1)
tk.Label(overlay, text="Loading...", fg="white", bg="#000000", font=("Segoe UI", 20)).place(relx=0.5, rely=0.5, anchor="center")
overlay.lift()                  # make sure it is on top
...
overlay.place_forget()          # remove when done

A centered dialog body or splash screen needs only place(relx=.5, rely=.5, anchor="center").

Moving widgets for animation, since place_configure(x=...) changes position without a relayout of siblings:

Python
def slide(step=0):
    box.place(x=10 + step * 4, y=60)
    if step < 40:
        root.after(16, slide, step + 1)

Stacking order

Overlapping widgets appear in creation order, with later widgets on top. Change it with widget.lift() (raise to top) and widget.lower(), or tkraise(). This is the main reason to prefer place for overlays: pack and grid never overlap widgets.

place_forget and friends

Python
widget.place_forget()           # hide
widget.place_info()             # dict of options
widget.place_configure(x=50)    # change options
parent.place_slaves()           # widgets placed in this parent

When NOT to use place

  • Forms and tables. Hard-coded numbers break when fonts, DPI or translations change; use grid.
  • Resizable windows with content that should reflow. pack and grid negotiate size automatically.
  • Anything with many widgets. Every widget needs its own position, and one change forces many edits.

A good rule: build the layout with grid/pack, and reach for place only for the one or two widgets that need to float above or outside the flow. Do not mix place with pack or grid for the same widget, but they may coexist in the same parent for different widgets: placed widgets do not take part in the other manager's sizing. See Responsive Layouts for window-resizing strategies that avoid fixed positions.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. How do you center a widget in its parent with place()?

    relx and rely give the parent's midpoint, and anchor='center' puts the widget's own center on it.
  2. 2. What is the final x when relx=0.5, x=10 in a parent 400 pixels wide (anchor 'nw')?

    Relative and absolute values add: 0.5 * 400 + 10 = 210.
  3. 3. Which is a good use of place()?

    place can overlap widgets, which makes it ideal for overlays and badges. Forms and tables belong to grid.
  4. 4. How do you bring an overlapping widget in front of another?

    lift() (also tkraise()) raises a widget in the stacking order; lower() sends it back.

Summary

  • place positions widgets by absolute pixels (x, y) or parent fractions (relx, rely, relwidth, relheight); the two add together.
  • anchor picks which point of the widget sits at the computed position.
  • It excels at overlays, badges, centered splash content and simple animation; stacking order is controlled with lift()/lower().
  • Avoid it for forms and flowing layouts; use grid or pack and keep place for the exceptions.

Next: Responsive Layouts