Skip to content

Commit

Permalink
add function to editClassSave
Browse files Browse the repository at this point in the history
  • Loading branch information
Mason-Dino committed Jul 18, 2024
1 parent af11790 commit 45992bf
Showing 1 changed file with 24 additions and 2 deletions.
26 changes: 24 additions & 2 deletions tabs/setting.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,15 @@ def settings(self):
self.classEditButtons.grid(row=2, column=0, columnspan=2, sticky="nsew", padx=10, pady=10)
self.classEditButtons.grid_columnconfigure((0,1), weight=1)

self.edit = customtkinter.CTkButton(master=self.classEditButtons, text="Edit Class", command=lambda: editClass(self, self.newClassName.get()))
self.edit = customtkinter.CTkButton(master=self.classEditButtons, text="Edit Class", command=lambda: editClassSave(self, self.newClassName.get()))
self.edit.grid(row=0, column=0, sticky="nsew", padx=10, pady=10)

self.delete = customtkinter.CTkButton(master=self.classEditButtons, text="Delete Class", command=lambda: deleteClass(self, self.classEdit.get()))
self.delete.grid(row=0, column=1, sticky="nsew", padx=10, pady=10)

self.level = customtkinter.CTkFrame(master=self.content)
self.level.grid(row=3, column=0, sticky="nsew", padx=10, pady=10)


def changeAppearanceMode(new_appearance_mode: str):
customtkinter.set_appearance_mode(new_appearance_mode)
Expand Down Expand Up @@ -101,4 +104,23 @@ def editClass(self, new_class: str):


def deleteClass(self, className: str):
print("hey")
print("hey")

def editClassSave(self, newClassName: str):
print(newClassName)

oldClassName = self.classEdit.get()

with open("setup.json", "r") as f:
setupDir = json.load(f)

for i in range(setupDir["numClasses"]):
if setupDir[f"class{i+1}"]["name"] == oldClassName:
setupDir[f"class{i+1}"]["name"] = newClassName
setupDir[f"class{i+1}"]["teacher"] = self.newInstructor.get()
setupDir[f"class{i+1}"]["subject"] = self.newClassType.get()

with open("setup.json", "w") as f:
json.dump(setupDir, f, indent=4)

messagebox.showinfo("Success", "Class Edited!")

0 comments on commit 45992bf

Please sign in to comment.