https://realpython.com/python-gui-tkinter/
'Frame' widgets are used for organizing the layout of other widgets in an application. Frames are best thought of as 'containers' for other widgets.
import tkinter as tk # Py3 root = tk.Tk() frame_a = tk.Frame(root) frame_b = tk.Frame(root) label_a = tk.Label(frame_a, text="In Frame A") label_a.grid() label_b = tk.Label(frame_b, text="In Frame B") label_b.grid() # Ordering of frames is determined here. frame_a.grid() frame_b.grid() root.mainloop() # run the tkinter event loop # root # / \ # frame_a frame_b # | | # label_a label_b
import tkinter as tk # Py3 border_effects = { "flat": tk.FLAT, "sunken": tk.SUNKEN, "raised": tk.RAISED, "groove": tk.GROOVE, "ridge": tk.RIDGE, } root = tk.Tk() c = 0 for relief_name, relief_obj in border_effects.items(): frame = tk.Frame(root, relief=relief_obj, borderwidth=5) frame.grid(row=0, column=c) c += 1 label = tk.Label(frame, text=relief_name) label.grid() root.mainloop() # run the tkinter event loop
Selected keyword arguments in Frame() master=root # the first argument bg="black" # set the background color to black ('bg' or 'background') width=50 # in pixels height=30 # in pixels borderwidth=5 # a border around a frame widget (default is 0, no border) relief="flat" # border decoration ("flat", "sunken", "raised", "groove", "ridge") bd=5 # 'borderwidth' or 'bd'