GUI Python with Tkinter – Part 5 – The place() geometry manager

Although the place() geometry manager is the least used geometry manager in Tkinter, it allows you to position widgets using the (x,y) coordinate system.

The most useful options for place() are:

  • Absolute positioning (x = N and y = N)
  • Relative positioning (relx, rely, relwidth, and relheight).

Other options that are commonly used with place() include width and anchor.

Example:

from tkinter import *
root = Tk()

# Absolute positioning
Button(root, text = "Absolute").place(x = 60, y = 20)
# x - horizontal placement; y - vertical placement

# Relative positioning
Button(root, text = "Relative").place(relx = 0.8, rely = 0.3, relwidth = 0.3, width = 40, anchor = NE)

root.mainloop()

Run the code in the terminal and you will get something like shown below:

The place() geometry manager

Try resizing the window and you will see that the button “Absolute” does not move during resizing while the “Relative” button changes its coordinates and size to accommodate the new size of the root window.

For a complete place() reference use the help command in terminal:

>>> import tkinter
>>> help(tkinter.Place)

Note:
The place() manager can be used with any geometry manager within the same frame.
The place() geometry manager is not usually used.
The pack() geometry manager is usually used for side-wise / top-down widget placement.
The grid() geometry manager is usually used for complex layouts.

Leave a Reply