如何在QTableWidget上显示和编辑CSV文件?

时间:2019-02-03 13:19:12

标签: python-3.x pyqt pyqt4

我正在为学校项目做一些工作,需要能够查看和编辑从PyQt的表小部件上显示的CSV文件,我创建了一个加载CSV文件以及写回csv的功能文件,但是我不确定如何在“表格”小部件上显示CSV文件以及如何使用户能够编辑表格。

我不太擅长编码,所以我真的不知道该怎么尝试。

import csv  
import os
def csv2list(file_name):
    list_name=[]
    with open(file_name) as csvfile:
        reader = csv.reader(csvfile)
        for row in reader:
            list_name.append(row)
    return list_name

def list2csv(list_name,file_name):
    #write back to the csv
    with open(file_name, 'w', newline='') as csvfile:
        writer = csv.writer(csvfile)
        writer.writerows(list_name)
    #it's a procedure, nothing returned

def launch_file(file_name):   
    os.startfile(file_name)

我希望能够看到表上显示的CSV文件,然后能够编辑信息并将其重写回CSV文件。

目前我没有结果,因为我只有功能

0 个答案:

没有答案