Tkinter Scrollbar explained with examples

Read Time:9 Minute, 56 Second

Table of Contents

Python provides several ways to create a graphical user interface. Tkinter is the most extensively used GUI technology out of all the possibilities. It’s a Python language interface to the Tk GUI toolkit offered by Python.

In this tutorial, you’ll learn about the Tkinter Scrollbar widget and how to link it to a scrollable widget.

Introduction to Tkinter scrollbar widget

A scrollbar allows you to see all of another widget’s content, usually greater than the available area. The Tkinter scrollbar widget is not included in any other Tkinter widgets, including Text and Listbox. A scrollbar, on the other hand, is a separate widget.

To use the scrollbar widget, you must do the following:

  • Create a scrollbar widget first.
  • Second, create a link between the scrollbar and a scrollable widget.

This widget includes a slide controller for implementing vertically scrolled widgets like Listbox, Text, and Canvas. Entry widgets can also have horizontal scrollbars added to them.



The easy syntax for making this widget is as follows:

We illustrate the use of ttk.Scrollbar constructor to build a scrollbar widget below:

The following is the syntax:

The scrollbar is located in the container, a window, or frame. On the other hand, the orient option determines whether the scrollbar should move horizontally or vertically when scrolling.


The scrollbar widget can communicate with the scrollable widget using the command argument. In addition, the scrollable widget must inform the scrollbar of the proportion of the whole content area that is currently visible.

The yscrollcommand and/or xscrollcommand options are available in any scrollable widget. You can also customize the scrollbar. Then assign a method to it:


  • master − This represents the parent window.
  • options − This is a collection of the most often used widget options. These parameters can be used as key-value pairs with commas between them.

Some of the parameter options available and their descriptions are as follows:

activebackground: The color changes when the mouse is over the slider and arrowheads.

bg: The color changes
when the mouse is not above the slider and arrowheads.


bd: The width of the 3-d borders around the trough’s circumference. And the width of the 3-d effects on the arrowheads and slider. The trough has no border by default. However, the arrowheads and sliders have a 2-pixel border.

Command: When the scrollbar is shifted, this procedure is invoked.

Cursor: When the mouse is over the scrollbar, the cursor appears.

elementborderwidth: The width of the arrowheads’ and slider’s borders. The default is elementborderwidth=-1, which implies that the borderwidth option’s value is used.

highlightbackground: When the scrollbar does not have focus, this is the color of the focus highlight.


Highlightcolor: When the scrollbar has the focus, this is the focus highlight color.

Highlightthickness: The emphasis highlights thickness. Also, the default value is 1. To disable the display of the focus highlight, set it to 0.

jump: When a user drags the slider, this option determines what happens. Every minor drag of the slider typically (jump=0) causes the command callback to be called. If this option is set to 1, the callback is not be triggered until the user releases the mouse button.

orient: For a horizontal scrollbar, use orient=HORIZONTAL, and for a vertical scrollbar, use orient=VERTICAL.

repeatdelay: This setting determines how long you must keep button 1 in the trough before the slider begins moving in the same direction repeatedly. The repeatdelay=300 value is the default, and the units are milliseconds.


repeatinterval: repeatinterval

takefocus: Normally, a scrollbar widget is used to tab the focus. If you don’t want this behavior, set takefocus=0.

troughcolor: The appearance of the trough.

width: The scrollbar’s width (its y dimension if horizontal, and its x dimension if vertical). The default value is 16.


The following methods are available on scrollbar objects. We look at the respective methods and their descriptions.



Returns two values (a, b) that describe the slider’s current position. For horizontal and vertical scrollbars, the a value indicates the position of the left or top edge of the slider; the b value indicates the position of the right or bottom edge.

set ( first, last )

Set w’s xscrollcommand or yscrollcommand to the scrollbar’s set() method to connect a scrollbar to another widget w. The arguments’ meaning is the same as the get() process’s returned values.

Example 1: Tkinter Scrollbar

Example 2: Tkinter scrollbar widget

Scrollable widgets come in a variety of forms, including text widgets. A simple user interface consisting of Text and Scrollbar widgets is demonstrated in the following program:


Tkinter Scrollbar explained with examples
Tkinter scrollbar widget

Key process pointers

  • Using ttk, make a scrollbar.
  • scrollingbar (orient, command)
  • Orientation can be either ‘vertical’ or ‘horizontal.’
  • The yview or xview property of the scrollable widget related to the scrollbar can be used as the command.
  • Set the scrollable widget’s yscrollcommand attribute to link to the scrollbar.

Example 3: Tkinter Scrollbar

Example 4: Tkinter Scrollbar

Tkinter Scrollbar Grid in Python

Python’s grid Tkinter is a layout manager that arranges widgets in rows and columns. The rows are represented by the x-axis, while the y-axis represents the columns. This section will look at how to use Python Tkinter’s Grid Layout Manager to add a scrollbar to the Text widget.

According to the approach, the Text and Scrollbar widget is placed at row=0 and column=0. That is for the Text widget and column=1 for the Scrollbar widget.

  • Both widgets will display parallel to each other in this manner (line 19, 27).
  • We will lengthen the scrollbar in a north-south direction using sticky (line 27).
  • Finally, we’ll connect the scrollbar to the text box widget (line 29, 30)
  • Any widget is used in place of the text widget.

Here’s how to use Grid to make a Scrollbar.

We’ve established a text editor with the Text box widget in this code, and if the quantity of words exceeds the Text widget’s orientation, a scroll bar will emerge.


Tkinter Scrollbar Grid in Python
Tkinter Scrollbar Grid in Python

Tkinter Scrollbar Frame in Python

In Python Tkinter, a scrollbar applies to a Frame, allowing the user to scroll the screen horizontally or vertically.

  • It is not always possible to fill the screen with all the text. Since it makes the material less readable, it will also look unattractive on the screen.
  • Scrollbars are solely created for this issue. Thus, users can now scroll through the scrollbar to access significant textual content.
  • The simplest and most effective method is to apply a scrollbar to the Frame. Put them (the scrollbar and the other widgets) into the frame window and pack them differently.
  • Pack the scrollbars on the right and other widgets on the left, for example.
  • The implementation of scrollbars on the Frame widget in Python Tkinter is shown below.

In Python Tkinter, we have inserted a scrollbar and a Text box widget inside the frame. Subsequently, we used Pack layout manager to move the scrollbar to the right and the textbox to the left. It is shown on lines 19 and 27. Finally, code at lines 29 and 30 binds the Scrollbar and textbox together.

Tkinter Scrollbar Canvas in Python

A canvas is a blank canvas on which diagrams are drawn. We may also use it to place images and widgets (frames, text boxes, buttons, and so on) in addition to drawing.

  • We’ll learn how to add a scrollbar to a canvas in this part.
  • We’ll also make an application to show how to use the Python Tkinter Scrollbar on Canvas.
  • Canvas is used to construct a canvas widget in the program, followed by the window’s name where it will be displayed. Also, specify the canvas window’s width and height.

We’ve created a frame and placed a canvas and scrollbar widget inside it. Further, we’ve bound horizontal and vertical scrollbars to the canvas.

Tkinter Scrollbar Text Box in Python

We’ve used Scrollbar on Text Widget in this area. This program’s output will resemble the Python Tkinter Scrollbar Frame.


  • We added the scrollbar to the Frame widget in Python Tkinter Scrollbar Frame, but we’ll apply it to the Text widget directly here.
  • In Python Tkinter, we constructed a Text widget and saved it to LEFT.
  • Then, we made a Scrollbar widget and positioned it to the RIGHT.
  • Lines 15 and 23 contain the Pack() code utilized as a layout manager.

Tkinter Scrollbar in Python Isn’t Working

We’ll look at why the scrollbar isn’t working in this section. Also, while implementing the scrollbar in Python Tkinter, we’ll discuss frequent issues and how to fix them.

Missing Layout manager: If you don’t see the scrollbar on the screen, the first thing to look for is whether the scrollbar widget positioning is by the layout manager, which can be pack, grid, or in place.

Appearing Small: On the chance that the Scrollbar in Python Tkinter seems to be too small,

  • use sticky and change the scrollbar to NS for vertical Scrollbar and EW for horizontal Scrollbar if you’re using Grid layout manager.
  • Use fill=X for horizontal scrollbars and fill=Y for vertical scrollbars if you’re using Pack layout manager (s).

Tkinter Scrollbar Text Widget in Python

We’ve used Scrollbar on Text Widget in this area. This program’s output will resemble the Python Tkinter Scrollbar Frame.

  • We added the scrollbar to the Frame widget in Python Tkinter Scrollbar Frame, but we’ll apply it to the Text widget directly here.
  • In Python Tkinter, we constructed a Text widget and saved it to LEFT.
  • Then, we made a Scrollbar widget and positioned it to the RIGHT.
  • The Pack() code, utilized as a layout manager, may be found on lines 15 23.

Tkinter Scrollbar Orientation in Python

The Orient option in the Python Tkinter scrollbar allows us to change the scrollbar from horizontal to vertical positions.


  • Scrollbars are used on widgets such as text boxes, frames, and lists.
  • Vertical scrollbars, horizontal scrollbars, or both could be required.
  • The following command is used to add scrollbars.
  • The variables lb and sb refer to the list box and the scrollbar.

We’ve changed the scrollbar’s direction to vertical in this code, so users can now scroll up and down to access the information. Line 19 is where you’ll find the code.

Python Tkinter code for a horizontally oriented Scrollbar

In this Python Tkinter code, we’ve constructed a horizontal scrollbar. You can see that we’ve set the scrollbar’s orientation to horizontal on line 19.

We’ve set the scrollbar’s orientation to horizontal in this output. Users can now view the material by scrolling right and left.


The scrollbar widget is responsible for scrolling down the content of other widgets such as listboxes, text boxes, and canvases. The horizontal scrollbars can, however, be added to the Entry widget.

A Scrollbar alludes to a Python Tkinter widget that allows continuous data to be scrolled across the screen in a preset direction. The direction can be vertical or horizontal. Scrollbars are added when the content exceeds the screen orientation to allow the user to navigate to previously viewed information in either a right-to-left or upward-to-downward direction.


In Python, layout managers like Place(), Grid(), and Pack() are used to position Tkinter widgets. These techniques are used to place the scrollbar widget on the application window.


WP Ad Inserter plugin for WordPress

Tag Cloud

Java Java Logical Programs OTP Generation in Java python Recursion youtube video ASCII Upper and Lower Case blockchain javascript graph learn to code software development Successful Software Engineers breadth first search Java Array Programs Java Programs Uncategorized android ios programming kotlin web-development django data sql cybersecurity database swiftui serverless aws swift rust react background-position gradients loader mask grid nth-child pseudo elements indieweb WordPress Print Array without brackets C++ factorial Java String Programs Final Keyword Static Variable Axie Infinity Cryptokitties NFT games tool inserting MISC Tips Codes python code python projects python3 system info python project Bigginers How to Do Integrations Payment Gateways PHP checkout page in php Implement stripe payment gateway in Step by step in PHP integrate stripe gatway in php mysql payment gateway integration in php step by step payment gateway integration in php step by step with source code payment gateway integration in website PHP Integrate Stripe Payment Gateway Tutorial PHP shopping cart checkout code shopping cart in php stripe php checkout PHP/MySQL/JSON best international payment gateway does google pay accept international payments how to accept international payments in india paytm payment gateway razorpay codeigniter github razorpay custom checkout github razorpay get payment details razorpay integration in codeigniter github razorpay international payments Razorpay payment gateway integration in CodeIgniter razorpay payment gateway integration in php code Razorpay payment gateway integration with PHP and CodeIgniter Razorpay payment gateway setup in CodeIgniter Library & Frameworks Tips & Tricks UI/UX & Front-end coding birds online html code for google sign in login with google account in PHP login with google account using javascript login with google account using javascript codeigniter login with google account using php login with google account using php source code
PostgreSQL vs MySQL: Which SQL Platform Should You Use? Previous post PostgreSQL vs MySQL: Which SQL Platform Should You Use?
How to change the Tkinter label text Next post How to change the Tkinter label text

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.