Scrollbar Widget in Tkinter (GUI Programming) – Python Tkinter Tutorial

Scrollbar Widget in Tkinter Python provides a vast number of libraries for GUI application development. Tkinter is the widely used library for GUI application development. Using the Tkinter library of python which carries large numbers of widgets, we can easily create a Graphical User Interface for our application.

Scrollbar: The scrollbar widget in Tkinter provides a slide controller functionality to the application that is used to implement vertically scrolling options to widgets, such as Text editor, Canvas and List box etc.
We can also use a horizontally scrolling option with widgets.

Syntax: 

scroll=Scrollbar(root, orient=VERTICAL, options*)

scroll bar in tkinter

Let’s see one example to understand the concept better

Example 1: 

from tkinter import *
#setting up parent window
root = Tk()

textbox=Text(root, width=40, height=13, wrap=WORD)
textbox.grid(row=0, column=0)

scroll=Scrollbar(root, orient=VERTICAL, command= textbox.yview)
scroll.grid(row=0, column=1, sticky=N+S)
textbox.config(yscrollcommand=scroll.set)

root.geometry("350x220")
root.title("PythonLobby.com")
root.mainloop()

Output:
scroll bar widget in tkinter

scroll bar widget example

Detailed explanation of program:

  • First, we have imported all the required libraries and modules of Tkinter using import *.
  • Then we have initialized root as an object for Tk() class for creating a root window.
  • Here we implemented scroll bar in out text editor widget. So, that’s why we first created text editor.
  • After creating text editor, we initialized object scroll using Scroll function including parameters root, orient and command.
  • Here we are using geometry manager as grid geometry manager.
  • As we have already created text editor and now scrollbar.
  • Next we have implemented/integrated the text editor with scroll bar.