HBa*_*iri 4 python text tkinter widget
我有一个字符串列表,我想在Tkinter文本小部件中打印这些字符串,但我无法在新行中插入每个字符串。
我试过这个但没有用:
ls = [a, b, c, d]
for i in range(len(lst)):
text.insert(1.0+i lines, ls[i])
Run Code Online (Sandbox Code Playgroud)
'\n'
手动附加换行符 ( ):
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()
Run Code Online (Sandbox Code Playgroud)
顺便说一句,您不需要使用索引来迭代列表。只需迭代列表。并且不要list
用作变量名。它隐藏内置 function/type list
。