我试图弄清楚如何在tkinter的网格中显示.csv
文件,但在网上没有找到太多。
这是我的进展。
import tkinter
root = tkinter.Tk()
for r in range(3):
for c in range(4):
tkinter.Label(root, text='R%s/C%s'%(r,c),borderwidth=1 ).grid(row=r,column=c)
root.mainloop()
如何使用相同的方法读取.csv
文件?
2条答案
按热度按时间mpbci0fu1#
您可以使用python csv模块中的reader来读取文件。Reader接受一个.csv文件作为输入,然后可以像表一样迭代。我包含了代码、一个示例.csv文件和我的结果。
代码:
CSV文件:
结果:
u1ehiz5o2#
而不是标签使用树视图这样,它会更有效。
我只是初始化Treeview,用csv模块读取csv并在Treeview中插入列和行数据。
结果See the result here