

The values (0, 0) tell the canvas on which position to draw the window. Next up we have to tell the canvas to actually draw the scrollable_frame inside itself: canvas.create_window((0, 0), window=scrollable_frame, anchor="nw")

The change is we modify the canvas' scrollregion to have a size of canvas.bbox("all").Ĭalling canvas.bbox("all") gives us a 4-value tuple describing the position of two corners of a rectangle which is the scroll region. Only when it changes size do we want to change any of the scrolling properties. usually when we add or remove widgets from within it. The event we're binding here triggers whenever the scrollable_frame changes size-i.e. This is necessary because we must tell the canvas how large the frame will be, so that it knows how much it can scroll: scrollable_frame.bind(
#Tkinter textbar with scrollbar code#
Now let's add some code that will call a function whenever the contents of the scrollable frame change.

Scrollbar = ttk.Scrollbar(container, orient="vertical", command=canvas.yview) We will create it, giving it the canvas as its container, but instead of using Pack or Grid, we will using the canvas' create_window method to create a window within the canvas that shows the scrollable frame's content.Ĭreating the widgets is straightforward enough: import tkinter as tk However, the scrollable frame will behave differently. you place them in their container and then use Pack or Grid).

Self.scrollbar = tk.Scrollbar(self.window, orient=tk.HORIZONTAL) The horizontal scroll bar is used to scroll the widgets like Text and Entry in the horizontal orientation. When the user moves the slider of Scrollbar, it calls the yview method with the proper argument. Set command of the Scrollbar to the yview of the Listbox.yscrollcommand is scrollable widgets’ option that is controlled by a scrollbar, and is used to communicted with vertical scrollbars. Set yscrollcommand callback to set of Scrollbar.We need configure both Listbox and Scrollbar to connect them together correctly. self.listbox = tk.Listbox(self.window, yscrollcommand=) Self.listbox = tk.Listbox(self.window, yscrollcommand=) Self.scrollbar = tk.Scrollbar(self.window) The Tkinter Scrollbar widget is normally used to scroll widgets like ListBox, Text or Canvas vertically, or Entry horizontally.
