
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Attach Scrollbar to Text Widget in Tkinter
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
Example
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 win.geometry("650x250") #Create an instance of Text Widget ScrolledText(win).pack() win.mainloop()
Output
Running the above code will display a window with a text widget that supports multiline user Input and a native scrollbar.