I have a list of strings, and I want to print those strings in a Tkinter text widget, but I can't insert each string in a new line.
I tried this but didn't work:
ls = [a, b, c, d]
for i in range(len(lst)):
text.insert(1.0+i lines, ls[i])
Append newline ('\n'
) manually:
from Tkinter import * # from tkinter import *
lst = ['a', 'b', 'c', 'd']
root = Tk()
t = Text(root)
for x in lst:
t.insert(END, x + '\n')
t.pack()
root.mainloop()
BTW, you don't need to use index to iterate a list. Just iterate the list. And don't use list
as a variable name. It shadows builtin function/type list
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With