- Trending Categories
- Data Structure
- Operating System
- C Programming
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to attach a Scrollbar to a 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
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()
Running the above code will display a window with a text widget that supports multiline user Input and a native scrollbar.
- How to attach a vertical scrollbar in Tkinter text widget?
- How to attach a vertical scrollbar to a Treeview using Tkinter?
- Attach scrollbar to listbox as opposed to window in Tkinter
- How to highlight text in a tkinter Text widget?
- Printing a list to a Tkinter Text widget
- How to create hyperlink in a Tkinter Text widget?
- How to erase everything from a Tkinter text widget?
- How to insert a temporary text in a tkinter Entry widget?
- Add advanced features to a tkinter Text widget
- How to set default text for a Tkinter Entry widget?
- How to clear the contents of a Tkinter Text widget?
- How to get a horizontal scrollbar in Tkinter?
- How do I center the text in a Tkinter Text widget?
- How to take input in a text widget and display the text in tkinter?
- How to center a Tkinter widget?