Pack#
In Tkinter, the pack()
method is a geometry manager provided by the Frame and Tk (root) widgets. It is used to organize and position widgets within a container using a packing algorithm. The pack()
method arranges widgets in a one-dimensional manner, either horizontally or vertically, filling the available space.
This page focuses on its features.
import os
from pathlib import Path
os.chdir(str(Path(os.getcwd()).parent))
import tkinter as tk
from tkinter import ttk
from tkinter_files.screenshot import take_screenshot
side#
The side parameter in the pack()
method of widgets is used to specify the side or edge of the container where a widget should be packed. It determines the direction in which widgets are arranged within the available space.
Possible options are tk.LEFT
, tk.TOP
, tk.RIGHT
and tk.BOTTOM
. The behaviour of objects added using all these arguments is described in the following example.
root = tk.Tk()
root.geometry("250x250")
btn1 = ttk.Button(text="BOTTOM")
btn1.pack(side=tk.BOTTOM)
btn2 = ttk.Button(text="RIGHT")
btn2.pack(side=tk.RIGHT)
btn3 = ttk.Button(text="LEFT")
btn3.pack(side=tk.LEFT)
btn4 = ttk.Button(text="TOP")
btn4.pack(side=tk.TOP)
root.after(200, take_screenshot, root)
root.mainloop()
