almost done
This commit is contained in:
BIN
assets/0.jpg
Normal file
BIN
assets/0.jpg
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 8.8 KiB |
BIN
assets/1.jpg
Normal file
BIN
assets/1.jpg
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 471 KiB |
BIN
assets/2.jpg
Normal file
BIN
assets/2.jpg
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 148 KiB |
10
libs.py
10
libs.py
@@ -1,4 +1,7 @@
|
||||
import json
|
||||
from PIL import Image
|
||||
import io
|
||||
import os
|
||||
|
||||
def write_json(key, value):
|
||||
path = 'db.json'
|
||||
@@ -81,3 +84,10 @@ def add_child(child_id, name, birth):
|
||||
data['children'].append(new_child)
|
||||
|
||||
write_json('children', data['children'])
|
||||
|
||||
def get_pic(id):
|
||||
image = Image.open(f"assets/{id}.jpg")
|
||||
image.thumbnail((200, 200))
|
||||
bio = io.BytesIO()
|
||||
image.save(bio, format="PNG")
|
||||
return bio.getvalue()
|
||||
49
main.py
49
main.py
@@ -1,5 +1,4 @@
|
||||
import PySimpleGUI as sg
|
||||
|
||||
import time
|
||||
from libs import *
|
||||
|
||||
@@ -23,6 +22,7 @@ def login():
|
||||
if event == sg.WINDOW_CLOSED or event == 'Sair':
|
||||
break
|
||||
|
||||
if event == 'Login':
|
||||
if validate_login(values['-USERNAME-'], values['-PASSWORD-']):
|
||||
window.close()
|
||||
return True
|
||||
@@ -35,27 +35,26 @@ def login():
|
||||
window.close()
|
||||
return False
|
||||
|
||||
|
||||
def main():
|
||||
if login():
|
||||
print("Login sucessful")
|
||||
else:
|
||||
print("Login unsucessful")
|
||||
##########################################################################################
|
||||
sg.theme('BlueMono')
|
||||
|
||||
info_col = [[sg.T('Name: '), sg.T('', key='-NAME-')],
|
||||
def main_menu():
|
||||
sg.theme('BlueMono')
|
||||
info_col = [
|
||||
[sg.T('ID: '), sg.T('', key='-ID-')],
|
||||
[sg.T('Name: '), sg.T('', key='-NAME-')],
|
||||
[sg.T('Birth: '), sg.T('', key='-BIRTH-')],
|
||||
[sg.T('ID: '), sg.T('', key='-ID-')]]
|
||||
[sg.Image(data=get_pic(0), key='-IMAGE-')]
|
||||
]
|
||||
|
||||
|
||||
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')]
|
||||
[sg.Listbox(values=[row[1] for row in get_children()], size=(30, 17), key='-CHILDREN-', enable_events=True), sg.Col(info_col)],
|
||||
[sg.Column([[sg.Button('Add'), sg.Button('Remove')]], justification='center')]
|
||||
]
|
||||
|
||||
window = sg.Window('Children App', layout)
|
||||
|
||||
window = sg.Window('Children App', layout, finalize=True)
|
||||
window.set_min_size((500,350))
|
||||
|
||||
while True:
|
||||
event, values = window.read()
|
||||
@@ -68,6 +67,7 @@ while True:
|
||||
window['-NAME-'].update(name)
|
||||
window['-BIRTH-'].update(birth)
|
||||
window['-ID-'].update(id)
|
||||
window['-IMAGE-'].update(get_pic(id))
|
||||
|
||||
if event == 'Add':
|
||||
add_layout = [
|
||||
@@ -90,17 +90,30 @@ while True:
|
||||
|
||||
if event == 'Remove':
|
||||
|
||||
id_layout = [[sg.T('Enter ID to remove')],
|
||||
[sg.In(key='-ID-')],
|
||||
selected = values['-CHILDREN-'][0]
|
||||
|
||||
id_layout = [[sg.T(f'Você tem certeza que deseja remover {selected}?')],
|
||||
[sg.T(f'Essa ação é PERMANENTE e IRREVERSÍVEL!', text_color="red")],
|
||||
[sg.Button(button_text="OK")]]
|
||||
|
||||
id_window = sg.Window('Remove Child', id_layout)
|
||||
id_window = sg.Window('Remove Child', id_layout, element_justification='c')
|
||||
id_event, id_values = id_window.read()
|
||||
|
||||
if id_event == 'OK':
|
||||
remove_child_by_id(int(id_values['-ID-']))
|
||||
remove_child_by_id(get_child_by_name(selected)[0])
|
||||
window['-CHILDREN-'].update(values=[row[1] for row in get_children()])
|
||||
|
||||
id_window.close()
|
||||
|
||||
window.close()
|
||||
|
||||
###############################################
|
||||
def main():
|
||||
if login():
|
||||
print("Login sucessful")
|
||||
main_menu()
|
||||
else:
|
||||
print("Login unsucessful")
|
||||
# main()
|
||||
main_menu()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user