This is just another example. Two frames with different resizing. Includes a treeview widget.
import tkinter as tk
from tkinter import ttk
import random
import string
class MyApp:
def __init__(self, root):
self.root = root
self.root.title("Using grid with two frames")
# Lay out two frames on the root window
## first frame will contain two rows of control widgets
## this frame will be able to resize horizontally
frame_controls = tk.Frame(master=self.root, padx=10, pady=10)
frame_controls.grid(row=0,
column=0, sticky="ew")
## second frame will contain a treeview
## this frame will be able to resize vertically and horizontally
frame_treeview = tk.LabelFrame(master=self.root, padx=10, pady=10,
text="Image files")
frame_treeview.grid(row=2,
column=0, padx=5, pady=5,
sticky="nsew")
# Create widgets in the appropriate frames
## first frame, first row: a button, an entry box, and another button
self.button_dest = ttk.Button (master=frame_controls, text="Dest dir")
self.entry = ttk.Entry (master=frame_controls)
self.button_clear = ttk.Button (master=frame_controls, text="Clear")
## first frame, second row: two buttons
self.button_scale = ttk.Button (master=frame_controls, text="Scale")
self.button_upload = ttk.Button (master=frame_controls, text="Upload")
## second frame, third row: the treeview
self.tree = ttk.Treeview(master=frame_treeview,
columns=("original", "scaled", "status"),
show="headings")
self.tree.heading("original", text="Original")
self.tree.heading("scaled", text="Scaled")
self.tree.heading("status", text="Status")
## add a vertical scroll bar to the containing frame and configure to the treeview
self.vsb = ttk.Scrollbar(master=frame_treeview,
orient="vertical",
command=self.tree.yview)
self.tree.configure(yscrollcommand=self.vsb.set)
## add rows of random string values to the treeview (dummy data)
for _ in range(20):
self.tree.insert("",
tk.END,
values=("".join(random.choices(string.ascii_letters, k=8)),
"".join(random.choices(string.ascii_letters, k=8)),
"".join(random.choices(string.ascii_letters, k=8))))
# Lay out the widgets in the grid
pad = 5 # uniform padding
self.button_dest.grid(row=0,
column=0, padx=pad, pady=pad)
self.entry.grid (row=0,
column=1, padx=pad, pady=pad, sticky=tk.EW,
columnspan=2)
self.button_clear.grid(row=0,
column=3, padx=pad, pady=pad)
self.button_scale.grid(row=1,
column=0, padx=pad, pady=pad)
self.button_upload.grid(row=1,
column=1, padx=pad, pady=pad)
self.tree.grid(row=2,
column=0, padx=pad, pady=pad, sticky=tk.NSEW)
self.vsb.grid(row=2,
column=1, sticky=tk.NS)
# Configure resizing behavior
self.root.grid_rowconfigure(2, weight=1) # the frame-containing window must resize
self.root.grid_columnconfigure(0, weight=1) # otherwise the contained frames will not
frame_controls.grid_columnconfigure(2, weight=1) # make contained entry resize with window
frame_treeview.grid_rowconfigure(2, weight=1) # make the contained treeview resize vertically,
frame_treeview.grid_columnconfigure(0, weight=1) # and horizontally
if __name__ == "__main__":
root = tk.Tk()
app = MyApp(root)
root.mainloop()