How do I add a scrollbar in tkinter?
A scrollbar and the widget it scrolls have to know about each other, and that is two separate lines of setup. Almost every "my scrollbar does nothing" is one of the two missing.
import tkinter as tk
from tkinter import ttk
root = tk.Tk()
box = tk.Listbox(root)
bar = ttk.Scrollbar(root, orient="vertical", command=box.yview) # bar -> widget
box.configure(yscrollcommand=bar.set) # widget -> bar
box.pack(side="left", fill="both", expand=True)
bar.pack(side="right", fill="y")
for i in range(100):
box.insert("end", f"row {i}")
root.mainloop() What each half does
command=box.yview is the outward half: dragging the bar tells the widget to scroll. yscrollcommand=bar.set is the return half: the widget tells the bar how much is showing and where, which is what sizes and moves the thumb.
With only the first line the bar drags the list but its thumb stays full width and never moves, because nothing is reporting the position back. With only the second, the thumb tracks the view but dragging it does nothing. Both symptoms look like a broken scrollbar and are the same missing pair.
Horizontal scrolling uses the x pair
The same shape applies sideways with xview and xscrollcommand, and the bar needs orient="horizontal" and fill="x" when packed. A widget can carry both at once.
hbar = ttk.Scrollbar(root, orient="horizontal", command=box.xview)
box.configure(xscrollcommand=hbar.set)
hbar.pack(side="bottom", fill="x")Which widgets can be scrolled
Listbox, Text, Canvas and Treeview all support the pair. A plain Frame does not — frames have no view to scroll, which is why a scrollable panel of widgets is built on a Canvas instead and is its own recipe.
Packing it so it is actually visible
A vertical scrollbar needs fill="y" to stretch down its side; without it the bar is its natural height and looks stunted or vanishes. Pack the scrollbar and the widget into the same parent, with the widget expanding and the bar not.
Doing it without the lookup
Drop a Scrollbar on and choose which widget it drives from the inspector. The export writes both halves of the wiring, which is the part worth having done for you — there is no way to end up with the half-connected version.
Lay the window out visually and read the generated Python as you go.
Open the tkinter designer →