将 tkinter 输入框文本保存为 JSON 格式

saving tkinter entry box text to a JSON format

我正在尝试将 tkinter 输入框文本存储为 JSON 格式: 预期输出为:

{"objects": [{"neptun_code": "BVQYMZ", "result": "89", "mark": "4"}, {"neptun_code": "NHFKYM", "result": "95", "mark": "5"}]}

我的输出如下所示:

[{':', 'neptun_code', 'AUU4NA'}, {'result', ':', '98'}, {':', '5', 'mark'}]
[{':', 'neptun_code', 'BVQYMZ'}, {'result', ':', '86'}, {':', '5', 'mark'}]

我的代码如下所示:

    def __sendData(self):
        self.list = []
        for i in range(len(self.entry)):
            self.list.append({self.entryNames[i],":",self.entry[i].get()})
            self.entry[i].delete(0, END)
        self.counter+=1
        self.entries.append(self.list)

我的 tkinter GUI:

解决方案是创建一个 dict()(例如 jsondict )你想要保存的内容,然后像这样使用 json 模块:

with open(file_path, 'w') as fp:
    json.dump(jsondict, fp,indent=4)