我有一段 Treeview 代码,在我看来没问题,但没有显示名为 ski1.txt 的 txt 文件中的内容
#Create the treeview
skiTV = ttk.Treeview(ReportsFrame, height = 15, columns=('Ski ID', 'First Name', 'Surname', 'Email', 'Medical'))
skiTV.grid(row = 1, column = 0, columnspan = 2)
scrollbar = Scrollbar(ReportsFrame, orient = "vertical", command = skiTV.yview)
scrollbar.grid(row = 1, column = 1, sticky = "NSE")
skiTV.configure(yscrollcommand = scrollbar.set)
skiTV.heading('#0', text = 'Ski ID')
skiTV.column('#0', minwidth = 0, width = 120, anchor = 'center')
skiTV.heading('#1', text = 'First Name')
skiTV.column('#1', minwidth = 0, width = 100, anchor = 'center')
skiTV.heading('#2', text = 'Surname')
skiTV.column('#2', minwidth = 0, width = 100, anchor = 'center')
skiTV.heading('#3', text = 'Email')
skiTV.column('#3', minwidth = 0, width = 160, anchor = 'center')
skiTV.heading('#4', text = 'Medical')
skiTV.column('#4', minwidth = 0, width = 90, anchor = 'center')
#Customise the treeview
#ttk.Style().theme_use('default')
#ttk.Style().configure("Treeview.Heading", background = "White", foreground = "black", font = "Calibri 12 bold")
#ttk.Style().configure("Treeview.Column", font = "Calibri 12")
#put data into the treeview
ski_details = []
with open('ski1.txt', 'r') as csvfile:
reader = csv.reader(csvfile)
for row in reader:
if row == []:
pass
else:
ski_details.append(row)
csvfile.close()
#display the ski from the file
for row in ski_details:
if len(row) < 40:
continue
skiTV.insert('','end', text = row[0], values = (row[1],row[2],row[3],row[4])
txt 文件包含如下行
55545658,marc,grant,[email protected],N/A
36027144,samuel,jamison,[email protected],N/A
24894222,daniel,jamison,[email protected],N/A
有人可以给我一些建议,为什么它没有显示
要在树视图中显示的数据