Hi,
I'm new to Python and trying to code my first little app, I have difficulties reading data from a file.
The goal of the app is that the user enter data corresponding to a person in a GUI (Last Name, First Name, Rank and Service). These data are stored as a list in a json file.
I would like then the data to be displayed in a treeview, each item of the list in its own column, and that's where I'm stuck.
Here's my code:
If you have advices regarding the code or the way to store (json? sqlite? list? dict?...) they're more than welcome
I'm new to Python and trying to code my first little app, I have difficulties reading data from a file.
The goal of the app is that the user enter data corresponding to a person in a GUI (Last Name, First Name, Rank and Service). These data are stored as a list in a json file.
I would like then the data to be displayed in a treeview, each item of the list in its own column, and that's where I'm stuck.
Here's my code:
If you have advices regarding the code or the way to store (json? sqlite? list? dict?...) they're more than welcome

from tkinter import * from tkinter import ttk import json window=Tk() window.title("Add Record") window.geometry("720x500") tree=ttk.Treeview(window, columns=("Last Name", "First Name", "Rank", "Service")) tree.grid(column=0, row=4, columnspan=4, pady=5) tree.column("#0", width=0, minwidth=0) tree.column("#1", width=200) tree.column("#2", width=200) tree.column("#3", width=80) tree.column("#4", width=150) tree.heading("#1",text="Last Name") tree.heading("#2",text="First Name") tree.heading("#3",text="Rank") tree.heading("#4",text="Service") def Quit(): window.destroy() def AddRecord(): CRUMember=[txtLastName.get(), txtFirstName.get(), txtRank.get(), txtService.get()] with open("CRUMembers.json", "a") as file: json.dump(CRUMember, file) file.write("\n") txtLastName.delete(0, END) txtFirstName.delete(0, END) txtRank.delete(0, END) txtService.delete(0, END) txtLastName.focus() def DispRecord(): with open("CRUMembers.json") as file: for line in file: line=line.strip() CRUMember=file.readlines() for p in range(len(CRUMember)): tree.insert("", "end", values=(CRUMember[p], CRUMember[p+1], CRUMember[p+2], CRUMember[p+3])) lblLastName=Label(window, text="Last Name", font=("Calibri", "14")) lblLastName.grid(column=0, row=0, sticky=E, ipadx=5, padx=10, pady=5) lblFirstName=Label(window, text="First Name", font=("Calibri", "14")) lblFirstName.grid(column=0, row=1, sticky=E, ipadx=5, padx=10, pady=5) lblRank=Label(window, text="Rank", font=("Calibri", "14")) lblRank.grid(column=0, row=2, sticky=E, ipadx=5, padx=10, pady=10) lblService=Label(window, text="Service", font=("Calibri", "14")) lblService.grid(column=0, row=3, sticky=E, ipadx=5, padx=10, pady=10) txtLastName=Entry(window, width=30, font=("Calibri", "14")) txtLastName.grid(column=1, row=0) txtFirstName=Entry(window, width=30, font=("Calibri", "14")) txtFirstName.grid(column=1, row=1) txtRank=Entry(window, width=30, font=("Calibri", "14")) txtRank.grid(column=1, row=2) txtService=Entry(window, width=30, font=("Calibri", "14")) txtService.grid(column=1, row=3) txtLastName.focus() btnAddRecord=Button(window, text="Add Record", command=AddRecord, font=("Calibri", "14"), width=12) btnAddRecord.grid(column=2, row=0, padx=10, pady=5) btnDispRecord=Button(window, text="Display Records", command=DispRecord, font=("Calibri", "14"), width=12) btnDispRecord.grid(column=3, row=0, pady=5, sticky=E) btnQuit=Button(window, text="Quit", command=Quit, font=("Calibri", "14")) btnQuit.grid(column=3, row=5, pady=5, sticky=SE) window.mainloop()