How do i Print a list to a Tkinter Text widget

Published December 30, 2021

The Tkinter Text widget is used in the Python program to show data. We may show multi-line formatted text with various attributes and styles using the Text Widget. This Text widget primarily offers the user a text editor.

The Text widget also allows us to utilize the tabs and marks to navigate through the content. Within these text widgets, we can also post pictures and text. In this post, we'll look at how to print text into a Tkinter Text widget.

 

How to Print a List to a Tkinter Text Widget

Text widgets can hold a list of things, however, inserting a list of items requires iterating over each item in the list. Let's check the example here

 

from tkinter import *

win = Tk()

win.geometry("700x350")

n = ["Python", "C++", "C#", "Java", "Bootstrap", "C", "Kotlin"]

text = Text(win, width=80, height=15)

text.pack()

for n in n:

    text.insert(END, n + '\n')

win.mainloop()

 

 

Python Tkinter printing list in text

 

Article Contributed By :
https://www.rrtutors.com/site_assets/profile/assets/img/avataaars.svg

1298 Views