fixed updating records
This commit is contained in:
@@ -73,11 +73,9 @@ class Application:
|
||||
top_frame = tk.Frame(self.root)
|
||||
top_frame.pack(side=tk.TOP, fill=tk.X)
|
||||
button_width = 8
|
||||
tk.Button(top_frame, text="Load", command=self.load_file, width=button_width).grid(row=0, column=0)
|
||||
tk.Button(top_frame, text="Safe", command=self.save_file, width=button_width).grid(row=0, column=1)
|
||||
tk.Button(top_frame, text="Export CSV", command=self.export_csv, width=button_width).grid(row=0, column=2)
|
||||
tk.Button(top_frame, text="Insert", command=self.export_csv, width=button_width).grid(row=1, column=0)
|
||||
tk.Button(top_frame, text="Delete", command=self.export_csv, width=button_width).grid(row=1, column=1)
|
||||
tk.Button(top_frame, text="Insert", command=self.export_csv, width=button_width).grid(row=0, column=0)
|
||||
tk.Button(top_frame, text="Delete", command=self.export_csv, width=button_width).grid(row=0, column=1)
|
||||
|
||||
self.aktiv = tk.StringVar()
|
||||
self.firma = tk.StringVar()
|
||||
@@ -117,7 +115,7 @@ class Application:
|
||||
|
||||
self.table.bind("<ButtonRelease-1>", self.select_record)
|
||||
|
||||
self.load_file()
|
||||
self._load_file()
|
||||
|
||||
self.root.mainloop()
|
||||
|
||||
@@ -131,11 +129,23 @@ class Application:
|
||||
def update_record(self):
|
||||
if self.current_record is None:
|
||||
return
|
||||
values = (self.aktiv.get(), self.firma.get(), self.name.get(), self.strasse.get(), self.plz_ort.get())
|
||||
self.table.delete(self.current_record)
|
||||
self.table.insert('', self.current_record, values=values)
|
||||
values = {
|
||||
0: self.aktiv.get(),
|
||||
1: self.firma.get(),
|
||||
2: self.name.get(),
|
||||
3: self.strasse.get(),
|
||||
4: self.plz_ort.get(),
|
||||
}
|
||||
for key, value in values.items():
|
||||
self.table.set(self.current_record, key, value)
|
||||
|
||||
def load_file(self):
|
||||
entry_var_list = [self.aktiv, self.firma, self.name, self.strasse, self.plz_ort]
|
||||
for entry in entry_var_list:
|
||||
entry.set("")
|
||||
self.current_record = None
|
||||
self._save_file()
|
||||
|
||||
def _load_file(self):
|
||||
try:
|
||||
with open(self.json_file, "r", encoding="utf-8") as f:
|
||||
self.address_list = json.load(f)
|
||||
@@ -150,7 +160,8 @@ class Application:
|
||||
json.dump(self.address_list, f)
|
||||
self.populate_table()
|
||||
|
||||
def save_file(self):
|
||||
def _save_file(self):
|
||||
self.export_table_to_address_list()
|
||||
try:
|
||||
with open(self.json_file, "w", encoding="utf-8") as f:
|
||||
json.dump(self.address_list, f, indent=4, sort_keys=True)
|
||||
@@ -202,11 +213,19 @@ class Application:
|
||||
for index, item in enumerate(self.address_list):
|
||||
self.table.insert('', 'end', iid=index, values=item)
|
||||
|
||||
def export_table_to_address_list(self):
|
||||
self.address_list.clear()
|
||||
for child in self.table.get_children():
|
||||
self.address_list.append([])
|
||||
for value in self.table.item(child)['values']:
|
||||
self.address_list[-1].append(value)
|
||||
|
||||
def delete_all_table_items(self):
|
||||
for item in self.table.get_children():
|
||||
self.table.delete(item)
|
||||
|
||||
def show_error(self, message_title: str, message: str):
|
||||
@staticmethod
|
||||
def show_error(message_title: str, message: str):
|
||||
messagebox.showwarning(title=message_title, message=message)
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user