【问题标题】:How to insert data from csv file to treeview?如何将数据从 csv 文件插入树视图?
【发布时间】:2019-11-08 14:18:18
【问题描述】:

我在 tkinter 中有一个树视图:

self.progress_view = ttk.Treeview(dataWindow, columns = ('Customer', 'Product'), show = "headings")
    self.progress_view.heading('#1', text = 'Customer')
    self.progress_view.heading('#2', text = 'Product')
    self.progress_view.pack()

和一个 csv 文件:

Customer, Product
Customer 1, Almonds
Customer 2, Flaked Almonds
Customer 3, Walnuts

如何更改此代码:

def insert_Data_Custom(self):
    self.progress_view.insert("", 'end', values = )

根据 csv 值显示值?

客户填写客户树状视图和产品填写产品?

结论

基本上是把csv数据导入treeview。

【问题讨论】:

    标签: python tkinter


    【解决方案1】:

    您需要import csv。对于该函数,删除以下代码 self.progress_view.insert("", 'end', values = ) 并尝试以下操作:

    with open('file.csv') as f:
        reader = csv.DictReader(f, delimiter=',')
        for row in reader:
            customer = row['Customer']
            product = row['Product']
            self.progress_view.insert("", 0, values=(customer, product))
    

    从以下链接获得此信息:https://www.sourcecodester.com/tutorials/python/12494/python-import-csv-file-tkinter-table.html

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-03-29
      • 2014-05-03
      • 2019-03-15
      • 1970-01-01
      • 2020-01-19
      • 1970-01-01
      相关资源
      最近更新 更多