tkinter Scrolling widgets Scrolling a group of widgets


When a window contains many widgets, they might not all be visible. However, neither a window (Tk or Toplevel instance) nor a Frame are scrollable. One solution to make the window content scrollable is to put all the widgets in a Frame, and then, embed this Frame in a Canvas using the create_window method.

canvas = tk.Canvas(parent)
scroll_y = tk.Scrollbar(parent, orient="vertical", command=canvas.yview)

frame = tk.Frame(canvas)
# group of widgets
for i in range(20):
    tk.Label(frame, text='label %i' % i).pack()
# put the frame in the canvas
canvas.create_window(0, 0, anchor='nw', window=frame)
# make sure everything is displayed before configuring the scrollregion

canvas.pack(fill='both', expand=True, side='left')
scroll_y.pack(fill='y', side='right')