main menu implemented
This commit is contained in:
4
.gitignore
vendored
4
.gitignore
vendored
@@ -158,6 +158,4 @@ cython_debug/
|
|||||||
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
|
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
|
||||||
# and can be added to the global gitignore or merged into this file. For a more nuclear
|
# and can be added to the global gitignore or merged into this file. For a more nuclear
|
||||||
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
|
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
|
||||||
#.idea/
|
#.idea/
|
||||||
|
|
||||||
db.json
|
|
||||||
16
db.json
Normal file
16
db.json
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
{
|
||||||
|
"children": [
|
||||||
|
{
|
||||||
|
"birth": "11/11/2006",
|
||||||
|
"id": 1,
|
||||||
|
"name": "Josias"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"birth": "24/07/2008",
|
||||||
|
"id": 2,
|
||||||
|
"name": "Chris"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"password": "pass",
|
||||||
|
"username": "admin"
|
||||||
|
}
|
||||||
49
libs.py
49
libs.py
@@ -33,4 +33,51 @@ def validate_login(username, password):
|
|||||||
if password == read_json_value("password"):
|
if password == read_json_value("password"):
|
||||||
return True
|
return True
|
||||||
return False
|
return False
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
def get_children():
|
||||||
|
data = read_json()
|
||||||
|
children = []
|
||||||
|
|
||||||
|
if 'children' in data:
|
||||||
|
for child in data['children']:
|
||||||
|
children.append([child['id'], child['name'], child['birth']])
|
||||||
|
return children
|
||||||
|
|
||||||
|
def get_child_by_name(name):
|
||||||
|
data = read_json()
|
||||||
|
|
||||||
|
if 'children' in data:
|
||||||
|
for child in data['children']:
|
||||||
|
if child['name'] == name:
|
||||||
|
return [child['id'], child['name'], child['birth']]
|
||||||
|
return None
|
||||||
|
|
||||||
|
def remove_child_by_id(child_id):
|
||||||
|
data = read_json()
|
||||||
|
if 'children' in data:
|
||||||
|
updated_children = []
|
||||||
|
for child in data['children']:
|
||||||
|
if child['id'] != child_id:
|
||||||
|
updated_children.append(child)
|
||||||
|
|
||||||
|
data['children'] = updated_children
|
||||||
|
|
||||||
|
write_json('children', data['children'])
|
||||||
|
|
||||||
|
|
||||||
|
def add_child(child_id, name, birth):
|
||||||
|
data = read_json()
|
||||||
|
|
||||||
|
new_child = {
|
||||||
|
"id": child_id,
|
||||||
|
"name": name,
|
||||||
|
"birth": birth
|
||||||
|
}
|
||||||
|
|
||||||
|
if 'children' not in data:
|
||||||
|
data['children'] = []
|
||||||
|
|
||||||
|
data['children'].append(new_child)
|
||||||
|
|
||||||
|
write_json('children', data['children'])
|
||||||
63
main.py
63
main.py
@@ -41,5 +41,66 @@ def main():
|
|||||||
print("Login sucessful")
|
print("Login sucessful")
|
||||||
else:
|
else:
|
||||||
print("Login unsucessful")
|
print("Login unsucessful")
|
||||||
|
##########################################################################################
|
||||||
|
sg.theme('BlueMono')
|
||||||
|
|
||||||
main()
|
info_col = [[sg.T('Name: '), sg.T('', key='-NAME-')],
|
||||||
|
[sg.T('Birth: '), sg.T('', key='-BIRTH-')],
|
||||||
|
[sg.T('ID: '), sg.T('', key='-ID-')]]
|
||||||
|
|
||||||
|
|
||||||
|
layout = [
|
||||||
|
[sg.Text('Children')],
|
||||||
|
[sg.Listbox(values=[row[1] for row in get_children()], size=(30, 10), key='-CHILDREN-', enable_events=True), sg.Col(info_col)],
|
||||||
|
[sg.Button('Add'), sg.Button('Remove')]
|
||||||
|
]
|
||||||
|
|
||||||
|
window = sg.Window('Children App', layout)
|
||||||
|
|
||||||
|
while True:
|
||||||
|
event, values = window.read()
|
||||||
|
if event == sg.WIN_CLOSED:
|
||||||
|
break
|
||||||
|
if event == '-CHILDREN-':
|
||||||
|
selected = values['-CHILDREN-']
|
||||||
|
id, name, birth = get_child_by_name(selected[0])
|
||||||
|
|
||||||
|
window['-NAME-'].update(name)
|
||||||
|
window['-BIRTH-'].update(birth)
|
||||||
|
window['-ID-'].update(id)
|
||||||
|
|
||||||
|
if event == 'Add':
|
||||||
|
add_layout = [
|
||||||
|
[sg.T('Name')],
|
||||||
|
[sg.In(key='-NAME-')],
|
||||||
|
[sg.T('Birth')],
|
||||||
|
[sg.In(key='-BIRTH-')],
|
||||||
|
[sg.T('ID')],
|
||||||
|
[sg.In(key='-ID-')],
|
||||||
|
[sg.Button(button_text="OK")]
|
||||||
|
]
|
||||||
|
|
||||||
|
add_window = sg.Window('Add Child', add_layout)
|
||||||
|
add_event, add_values = add_window.read()
|
||||||
|
|
||||||
|
if add_event == 'OK':
|
||||||
|
add_child(int(add_values['-ID-']), add_values['-NAME-'], add_values['-BIRTH-'])
|
||||||
|
window['-CHILDREN-'].update(values=[row[1] for row in get_children()])
|
||||||
|
add_window.close()
|
||||||
|
|
||||||
|
if event == 'Remove':
|
||||||
|
|
||||||
|
id_layout = [[sg.T('Enter ID to remove')],
|
||||||
|
[sg.In(key='-ID-')],
|
||||||
|
[sg.Button(button_text="OK")]]
|
||||||
|
|
||||||
|
id_window = sg.Window('Remove Child', id_layout)
|
||||||
|
id_event, id_values = id_window.read()
|
||||||
|
|
||||||
|
if id_event == 'OK':
|
||||||
|
remove_child_by_id(int(id_values['-ID-']))
|
||||||
|
window['-CHILDREN-'].update(values=[row[1] for row in get_children()])
|
||||||
|
|
||||||
|
id_window.close()
|
||||||
|
|
||||||
|
window.close()
|
||||||
|
|||||||
Reference in New Issue
Block a user