Tkinter is a library in Python for developing GUI. It provides various widgets for developing GUI(Graphical User Interface). The Entry widget in tkinter helps to take user input, but it collects the input limited to a single line of text. Therefore, to create a Multiline entry text in tkinter there are a number of ways.
Methods to create multiline entry with tkinter:
- Using Text Widget
- Using ScrolledText widget
Method 1: Using Tkinter Text Widget
A text widget provides a multi-line text area for the user. The text widget instance is created with the help of the text class. It is also used to display text lines and also allows editing the text.
Text( root, optional parameters, ... )
The above output of the example lets the user enter text in multiple lines. But it does not show all the text entered by the user beyond the height of the text widget i.e., height=3. As it shows only 3 lines of text, therefore using a scroll bar for such multiline texts will solve the problem.
Example 2: Adding Scrollbar to text widget
Method 2: Using ScrolledText tkinter Widget
Instead of adding a scroll bar to a text widget as seen in example 2, we can directly use the ScrolledText tkinter widget for multiline entry by the user. This widget automatically adds the scroll bar as the text gets increased than the height of the scrolledText widget.
Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.
To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course. And to begin with your Machine Learning Journey, join the Machine Learning – Basic Level Course