I am trying to store tkinter entrybox text into a JSON format: The expected output is:
{"objects": [{"neptun_code": "BVQYMZ", "result": "89", "mark": "4"}, {"neptun_code": "NHFKYM", "result": "95", "mark": "5"}]}
My output looks like this:
[{':', 'neptun_code', 'AUU4NA'}, {'result', ':', '98'}, {':', '5', 'mark'}]
[{':', 'neptun_code', 'BVQYMZ'}, {'result', ':', '86'}, {':', '5', 'mark'}]
my code looks like this:
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)
My tkinter GUI:
The solution is to create a dict()
(eg jsondict
) of what you want to save and then use the json module like this:
with open(file_path, 'w') as fp:
json.dump(jsondict, fp,indent=4)