I want to display each row and column with correct values, but using tkinter widget i dont see the expected result. Expect is
('1', '2', '3', '4', '5')
('aa', 'bb', 'cc', 'dd', 'ee')
('!@', '%^', '&*', '@#', '@$')
('A', 'B', 'C', 'D', 'E')
but only ('A', 'B', 'C', 'D', 'E')
is displayed in all the rows. please help me to sort out the problem:
from tkinter import *
top=Tk()
for t in [("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[y])
top.state("zoomed")
top.mainloop()
You do not need this loop:
for t in [("1","2","3","4","5"),("aa","bb","cc","dd","ee"),("!@","%^","&*","@#","@$"),("A","B","C","D","E")]:
Instead:
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()
OUTPUT :
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.