
- 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
Printing a list to a Tkinter Text widget
The Tkinter Text widget is used to take multiline user text input. It provides many properties and built-in functions that can be used to customize the text widget. Let's suppose we need to create an application in which we want to display a list of items in a Text widget. To insert a list of items in a Text widget, we have to iterate over each item in the list and insert them in the Text widget. The following example demonstrates how to implement it.
Example
# Import the required library from tkinter import * # Create an instance of tkinter frame win=Tk() # Set the geometry win.geometry("700x350") # Add the list of items days= ["Sun", "Mon", "Tue","Wed","Thu","Fri","Sat"] text=Text(win, width=80, height=15) text.pack() # Iterate over each item in the list for day in days: text.insert(END, day + '\n') win.mainloop()
Output
Running the above code will display the days of week as the list in a text widget.
- Related Questions & Answers
- How to highlight text in a tkinter Text widget?
- Add advanced features to a tkinter Text widget
- How to erase everything from a Tkinter text widget?
- How to create hyperlink in a Tkinter Text widget?
- How to attach a Scrollbar to a Text widget in Tkinter?
- How to insert a temporary text in a tkinter Entry widget?
- How to set default text for a Tkinter Entry widget?
- How to clear the contents of a Tkinter Text widget?
- How to attach a vertical scrollbar in Tkinter text widget?
- How do I center the text in a Tkinter Text widget?
- Get the text of a button widget in Tkinter
- Undo and redo features in a Tkinter Text widget
- Underline Text in Tkinter Label widget
- Select all text in a Text widget using Python 3 with tkinter
- How do I give focus to a python Tkinter text widget?
Advertisements