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 )
Various possible options in Tkinter ScrollBar:
|This option is used to set background color of widget under focus.
|This option helps us to set the normal background colour of the widget.
|This option helps us to set the border size around the widget.
|This option helps us to mention a function to every time when ScrollBar will change its state.
|This option helps us to set the style of cursor like an arrow, dot etc
|This option is used to set a border around arrowheads and slider. By default elementborderwidth=1.
|This option is used to set the color of the focus highlight when the widget is not having the focus.
|This option is used to set highlight colour shown to the widget under focus.
|This option is used to set the thickness of hight focus. By default highlightthickness=1.
|This option is used to control the behaviour of the scroll jump.
|This option is used to set the orientation of scroll bar HORIZONTAL or VERTICAL.
|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.
|This option is used to set the repeat interval. By default, it is 100.
|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.
|This option is used to set the colour of the trough.
|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.
|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.