add delete function
This commit is contained in:
parent
1470cbfe2a
commit
2d1db0070c
@ -1 +1 @@
|
|||||||
{"dfd": {"name": "dfd", "country": "fa", "members": []}, "dfaaa": {"name": "dfaaa", "country": "fa", "members": [{"name": "d", "army": "a"}, {"name": "fds", "army": "adfs"}]}, "Daniel": {"name": "Daniel", "country": "Austria", "members": []}, "Sarah": {"name": "Sarah", "country": "s", "members": []}, "dfg": {"name": "dfg", "country": "fdsa", "members": []}, "Test": {"name": "Test", "country": "asd", "members": []}}
|
{"Swiss List": {"name": "Swiss List", "country": "Switzerland", "members": [{"name": "Gianni", "army": "Daughters"}, {"name": "Jonas", "army": "Seraphon"}, {"name": "Mirco", "army": "Beasts"}, {"name": "Sebastien", "army": "Lumineth"}, {"name": "Quasim", "army": "Cities"}, {"name": "Stefan", "army": "Idoneth"}, {"name": "Thomas", "army": "Stormcasts"}, {"name": "Tobias", "army": "Ironjawz"}]}, "Austrian List": {"name": "Austrian List", "country": "Austria", "members": [{"name": "Bene", "army": "Beasts"}, {"name": "Stefan", "army": "Lumineth"}, {"name": "Martin", "army": "Stormcasts"}, {"name": "Daniel", "army": "Seraphon"}, {"name": "Roli", "army": "Ironjawz"}, {"name": "Thomas", "army": "Daughters"}, {"name": "Tobi", "army": "Idoneth"}, {"name": "Flo", "army": "Slaves"}]}}
|
4
main.py
4
main.py
@ -18,8 +18,8 @@ class App(tk.Tk):
|
|||||||
|
|
||||||
container = ttk.Frame(self, padding="100 100")
|
container = ttk.Frame(self, padding="100 100")
|
||||||
container.pack()
|
container.pack()
|
||||||
container.columnconfigure(0, minsize=500, weight=1)
|
container.columnconfigure(0, minsize=700, weight=1)
|
||||||
container.rowconfigure(0, minsize=300, weight=1)
|
container.rowconfigure(0, minsize=500, weight=1)
|
||||||
|
|
||||||
self.frames = {}
|
self.frames = {}
|
||||||
|
|
||||||
|
21
team.py
21
team.py
@ -2,6 +2,7 @@ import json
|
|||||||
import os
|
import os
|
||||||
import tkinter as tk
|
import tkinter as tk
|
||||||
from tkinter import ttk
|
from tkinter import ttk
|
||||||
|
from tkinter import messagebox
|
||||||
|
|
||||||
path = "data/team.json"
|
path = "data/team.json"
|
||||||
|
|
||||||
@ -20,6 +21,7 @@ class TeamsPage(tk.Frame):
|
|||||||
|
|
||||||
self.teamSelector.grid(column=1, row=1, sticky="ew")
|
self.teamSelector.grid(column=1, row=1, sticky="ew")
|
||||||
self.teamSelector.bind("<<ComboboxSelected>>", self.setActiveTeam)
|
self.teamSelector.bind("<<ComboboxSelected>>", self.setActiveTeam)
|
||||||
|
tk.Button(self, text="Delete", command=self.deleteTeam).grid(column=2, row=1, sticky="w")
|
||||||
|
|
||||||
if len(self.teams) == 0:
|
if len(self.teams) == 0:
|
||||||
self.teamSelector.state(["readonly"])
|
self.teamSelector.state(["readonly"])
|
||||||
@ -39,7 +41,7 @@ class TeamsPage(tk.Frame):
|
|||||||
def createTeam(self):
|
def createTeam(self):
|
||||||
self.activeTeam = None
|
self.activeTeam = None
|
||||||
self.teamSelector.selection_clear()
|
self.teamSelector.selection_clear()
|
||||||
|
self.teamKey.set("")
|
||||||
self.teamName.set("")
|
self.teamName.set("")
|
||||||
self.teamCountry.set("")
|
self.teamCountry.set("")
|
||||||
self.teamMembers = []
|
self.teamMembers = []
|
||||||
@ -54,6 +56,23 @@ class TeamsPage(tk.Frame):
|
|||||||
file.close()
|
file.close()
|
||||||
self.teamSelector["values"] = list(self.teams.keys())
|
self.teamSelector["values"] = list(self.teams.keys())
|
||||||
|
|
||||||
|
def deleteTeam(self):
|
||||||
|
key = self.teamKey.get()
|
||||||
|
confirmed = messagebox.askyesno(
|
||||||
|
message="Are you sure you want to delete team " + key + "?",
|
||||||
|
icon="question", title="Delete")
|
||||||
|
|
||||||
|
if confirmed:
|
||||||
|
self.loadTeams()
|
||||||
|
del self.teams[key]
|
||||||
|
|
||||||
|
file = open(path, "w")
|
||||||
|
file.write(json.dumps(self.teams))
|
||||||
|
file.close()
|
||||||
|
|
||||||
|
self.loadTeams()
|
||||||
|
self.createTeam()
|
||||||
|
|
||||||
def saveTeam(self):
|
def saveTeam(self):
|
||||||
key = self.teamKey.get()
|
key = self.teamKey.get()
|
||||||
name = self.teamName.get()
|
name = self.teamName.get()
|
||||||
|
Loading…
Reference in New Issue
Block a user