cosmicsraka.blogg.se

Tkinter textbar with scrollbar
Tkinter textbar with scrollbar






tkinter textbar with scrollbar

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")

tkinter textbar with scrollbar

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.

tkinter textbar with scrollbar

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).

  • A frame that will become the scrollable frameĪlmost all these widgets will work like normal Tkinter widgets (i.e.
  • A container frame for our canvas and scrollbar.
  • Let's start off by creating all the widgets we'll need. Often, the scrollable area matches the contents of the inner window-but it can also be different if we wish. In order to do so, we must also specify what the scrollable area will be. That means that we'll be able to set the Canvas size to whatever we want, and then when we scroll we'll be moving along the window inside it. The window can have as much content as we like, but it's the Canvas that we'll be placing inside our application. What we'll be doing is creating a Canvas, and inside it creating a window. The scrollable frame is what the user sees, and you can think of it as a "window" that lets you see into the scrollable area. The content (with the darkest background) is the "actual size", which usually is also the "scrollable area". That means that it can have an actual size larger than the screen size, and you can move the area you are viewing. (command=)Ĭorrespondingly, the callback of the horizontal scroll bar should be connected with the xview method but not yview.In Tkinter, only the Canvas widget is a natively scrollable container. To scroll the text horizontally, we need to set xscrollcommand to the set method of the Scrollbar, but not yscrollcommand as in the above example. It initiates a horizontal scroll bar by specifying the orient to be HORIZONTAL.

    tkinter textbar with scrollbar

    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.








    Tkinter textbar with scrollbar