
- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
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
How to code the tkinter "scrolledtext" module?
A widget in a Tkinter application can be configured easily by adding extensions and properties to it. The Text widget in tkinter is used to accept multiline user input. We can make the text inside the Text widget Scrollable by adding a scrollbar to it.
The ScrolledText Widget is also available in Tkinter Library. It is the combination of Text widget and Scrollbar widget which provides features like scrolling the text in an application. In order to use ScrolledText widget in an application, you must import it first. The scrolledtext widget works similar to the standardText widget. It includes all the properties and attributes that can be used extensively in the widget.
Example
# Import the tkinter library from tkinter import * from tkinter.scrolledtext import ScrolledText from lorem_text import lorem # Create an instance of tkinter frame win= Tk() # Set the size of the Tkinter window win.geometry("700x350") # Set the title of the window win.title("Scrolled Text") # Add ScrolledText widget size= 10 text= ScrolledText(win, width=40, height= 50) text.insert(END, lorem.paragraphs(10)) text.pack(fill= BOTH, side= LEFT, expand= True) win.mainloop()
Output
Executing the above code will display a multiline Text widget. The text inside the Text widget are scrollable. We can see even better output by adding wrapping feature in it.
- Related Questions & Answers
- How to use the "native" GUI look with Tkinter?
- What's the difference between "update" and "update_idletasks" in Tkinter?
- Difference between "grid" and "pack" geometry managers in Tkinter
- Difference between "fill" and "expand" options for tkinter pack method
- What does the "wait_window" method do in Tkinter?
- How to specify "ENTER" button functionality in Selenium WebDriver code?
- How to bind multiple events with one "bind" in Tkinter?
- Change the color of "tab header" in ttk.Notebook (tkinter)
- How to change the code "Yes" to 1 in an R data frame column?
- "static const" vs "#define" vs "enum" ?
- How to create "next" and "previous" buttons with CSS?
- How to show a window that was hidden using the "withdraw" method in Tkinter?
- Why do we use extern "C" in C++ code?
- The "E" and "e" custom specifiers in C#
- Java regex program to match parenthesis "(" or, ")".