Python Tkinter ScrollBar

In this tutorial, we will learn about Python Tkinter ScrollBar. Tkinter ScrollBar widget is used to make the content of other widgets scroll-able in Python application.

Syntax to add Python Tkinter ScrollBar:

w = Scrollbar (master, options)  
  • master: This represents the parent window.
  • options: Here is the list of most commonly used options for this widget.

Example Program of Python Tkinter ScrollBar:

# importing tkinter lib
from tkinter import *  
mainWindow = Tk()  


scrollbar = Scrollbar(mainWindow)
scrollbar.pack( side = RIGHT, fill = Y )

mylist = Listbox(mainWindow, yscrollcommand = scrollbar.set )
for line in range(100):

mylist.pack( side = LEFT, fill = BOTH )
scrollbar.config( command = mylist.yview )



Python Tkinter ScrollBar

Various possible options in Python Tkinter ScrollBar:

activebackgroundThis option is used to set background color of widget under focus.
bgThis option helps us to set the normal background colour of the widget.
bdThis option helps us to set the border size around the widget.
commandThis option helps us to mention a function to every time when ScrollBar will change its state.
cursorThis option helps us to set the style of cursor like an arrow, dot etc
elementborderwidthThis option is used to set a border around arrowheads and slider. By default elementborderwidth=1.
highlightbackgroundThis option is used to set the color of the focus highlight when the widget is not having the focus.
highlightcolorThis option is used to set highlight colour shown to the widget under focus.
highlightthicknessThis option is used to set the thickness of hight focus. By default highlightthickness=1.
jumpThis option is used to control the behaviour of the scroll jump.
orientThis option is used to set the orientation of scroll bar HORIZONTAL or VERTICAL.
repeatdelayThis option used to controls how long button one has to be held down before the slider starts moving in that direction repeatedly. The default time is repeatdelay=300 milliseconds.
repeatintervalThis option is used to set the repeat interval. By default, it is 100.
takefocusThis option is used to set the focus of widget which is by default on. If you don’t want to keep it on you can set this option to 0.
troughcolorThis option is used to set the colour of the trough.
widthThis helps us to set the width of the widget.

Python Tkinter ScrollBar Methods:

After learning about various available options in Python Tkinter ScrollBar Its time to check out some available methods for Python Tkinter ScrollBar widget.

get()This method returns the two numbers a and b which represents the current position of the scrollbar.
set ( first, last )This method used to connect the scrollbar to the other widget.
Spread the love