How to attach a Scrollbar to a Text widget in Tkinter?

TkinterPythonServer Side ProgrammingProgramming

Tkinter Text widget is used to accept multiline user Input. It is similar to Entry Widget but the only difference is that Text widget supports multiple line texts. In order to create a Text widget, we have to instantiate a text object.

Adding multiple texts will require to add the ScrollBar. In order to add a scrollbar in the text widget, we can call the ScrolledText(root) function. This function generally creates a text field with a scrollbar.

The ScrolledText(root) function resides in Tkinter ScrolledText Module. We can import it using the following command,

from tkinter.scrolledtext import ScrolledText


In this example, we will create a Text widget and then add a scrollbar to it.

#Import the library
from tkinter import *
from tkinter.scrolledtext import ScrolledText

#Create an object of tkinter window or frame
win = Tk()

#Define the geometry of window

#Create an instance of Text Widget



Running the above code will display a window with a text widget that supports multiline user Input and a native scrollbar.

Published on 27-Mar-2021 06:05:17