The place()
manager organises widgets by placing them in a specific position in the parent widget. This geometry manager uses the options anchor
, bordermode
, height
, width
, relheight
, relwidth
,relx
, rely
, x
and y
.
Anchor
Indicates where the widget is anchored to. The options are compass directions: N, E, S, W, NE, NW, SE, or SW, which relate to the sides and corners of the parent widget. The default is NW (the upper left corner of widget)
Bordermode
Bordermode has two options: INSIDE
, which indicates that other options refer to the parent's inside, (Ignoring the parent's borders) and OUTSIDE
, which is the opposite.
Height
Specify the height of a widget in pixels.
Width
Specify the width of a widget in pixels.
Relheight
Height as a float between 0.0 and 1.0, as a fraction of the height of the parent widget.
Relwidth
Width as a float between 0.0 and 1.0, as a fraction of the width of the parent widget.
Relx
Horizontal offset as a float between 0.0 and 1.0, as a fraction of the width of the parent widget.
Rely
Vertical offset as a float between 0.0 and 1.0, as a fraction of the height of the parent widget.
X
Horizontal offset in pixels.
Y
Vertical offset in pixels.
Example
from tkinter import *
root = Tk()
root.geometry("500x500")
btn_height = Button(root, text="50px high")
btn_height.place(height=50, x=200, y=200)
btn_width = Button(root, text="60px wide")
btn_width.place(width=60, x=300, y=300)
btn_relheight = Button(root, text="Relheight of 0.6")
btn_relheight.place(relheight=0.6)
btn_relwidth= Button(root, text="Relwidth of 0.2")
btn_relwidth.place(relwidth=0.2)
btn_relx=Button(root, text="Relx of 0.3")
btn_relx.place(relx=0.3)
btn_rely=Button(root, text="Rely of 0.7")
btn_rely.place(rely=0.7)
btn_x=Button(root, text="X = 400px")
btn_x.place(x=400)
btn_y=Button(root, text="Y = 321")
btn_y.place(y=321)
root.mainloop()
Result