Creating a scrollable frame

There will come a time when writing applications with Tkinter when you will want to add a Scrollbar to the application as a whole, rather than an individual widget (such as the Text widget, which we have already covered). This is not a trivial task, since Tkinter will usually expand itself to show all of its containing widgets, or if the geometry is already set, will simply hide them underneath the bottom border of the window.

Let's take a look at what I mean. Open a new Python script and type the following short snippet:

import tkinter as tkwin = tk.Tk()for _ in range(30):    tk.Label(win, text="big label").pack(pady=20)win.mainloop()

If you run this file you should see a very tall window open up. You will see a ...

Get Tkinter GUI Programming by Example now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.