Tkinter:在Tkinter文本GUI小部件中显示项目列表

时间:2019-03-06 12:27:45

标签: python python-3.x tkinter

我想用正确的值显示每一行和每一列,但是使用tkinter小部件我看不到预期的结果。期望是

sbrk_r

,但所有行中仅显示('1', '2', '3', '4', '5') ('aa', 'bb', 'cc', 'dd', 'ee') ('!@', '%^', '&*', '@#', '@$') ('A', 'B', 'C', 'D', 'E') 。请帮助我解决问题:

('A', 'B', 'C', 'D', 'E')

1 个答案:

答案 0 :(得分:1)

您不需要此循环:

for t in [("1","2","3","4","5"),("aa","bb","cc","dd","ee"),("!@","%^","&*","@#","@$"),("A","B","C","D","E")]: 

相反:

from tkinter import *
top=Tk()
t = [("1","2","3","4","5"),("aa","bb","cc","dd","ee"),("!@","%^","&*","@#","@$"),("A","B","C","D","E")]

for x in range(4):
    for y in range(5):
            w = Text(top, width=15, height=2)
            w.grid(row=x,column=y)
            w.insert(END, t[x][y])

top.state("zoomed")
top.mainloop()

输出

out