-1

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:

enter image description here

  • 2
    You want a `dict` with a list of `dict`. Therefore you need a global: `{"objects": []}` object where you append `self.entries` which have to be `dict` instead of `list`. – stovfl May 14 '20 at 09:25

1 Answers1

0

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)
Jean-Marc Volle
  • 3,113
  • 1
  • 16
  • 20