.txt 文件中的数据未显示在树视图中

问题描述 投票:0回答:0

我在名为 ski1.txt 的文件中有文本,但 TreeView 是空的

示例文本是

35593906,robert,hendo,[email protected],N/A

98182541,Ben,Brown,[email protected],N/A

60884516,Dan,Dare,[email protected],自闭症

#---------------------------Components for Reports Frame
#Add image and heading to the frame
filename5 = 'skiier.png'
logo5 = PhotoImage(file = filename5)
headerlabel = Label(AddskiquizFrame, image = logo)
headerlabel.grid(row = 0, column = 0, columnspan = 1, sticky = W)

mainlabel5 = Label(ReportsFrame, text = 'Reports',fg = 'black', bg = 'White', font = 'Calibri 20 bold')
mainlabel5.grid(row =0, column = 1, pady = 10)

#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]))
    

数据显示在 TreeView 中

python tkinter insert treeview
© www.soinside.com 2019 - 2024. All rights reserved.