Python Tkinter ScrollBar

In this tutorial, we will learn about Python Tkinter ScrollBarTkinter 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()  

mainWindow.geometry("320x180")

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

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

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

mainWindow.mainloop() 

Various possible options in Tkinter ScrollBar:

Option Description
activebackground This option is used to set background color of widget under focus.
bg This option helps us to set the normal background colour of the widget.
bd This option helps us to set the border size around the widget.
command This option helps us to mention a function to every time when ScrollBar will change its state.
cursor This option helps us to set the style of cursor like an arrow, dot etc
elementborderwidth This option is used to set a border around arrowheads and slider. By default elementborderwidth=1.
highlightbackground This option is used to set the color of the focus highlight when the widget is not having the focus.
highlightcolor This option is used to set highlight colour shown to the widget under focus.
highlightthickness This option is used to set the thickness of hight focus. By default highlightthickness=1.
jump This option is used to control the behaviour of the scroll jump.
orient This option is used to set the orientation of scroll bar HORIZONTAL or VERTICAL.
repeatdelay This 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.
repeatinterval This option is used to set the repeat interval. By default, it is 100.
takefocus This 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.
troughcolor This option is used to set the colour of the trough.
width This helps us to set the width of the widget.

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.

Method DESCRIPTION
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
Scroll to Top