-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
45 lines (32 loc) · 1.39 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import PySimpleGUI as sg
from models import Diary, Entry
# first load the diary and get the existing entries
diary = Diary()
diary.load()
#sg.theme('DarkAmber') # Add a touch of color
# All the stuff inside your window.
layout = [ [sg.Text('Diary entries:')],
# add entries into multiline input
[sg.Multiline(diary.build_entries(), disabled=True, size=(125, 20), font=('Default', 14), key='_ENTRIES_')],
[sg.Text('Type your diary entry:')],
[sg.Multiline('', size=(125, 15), font=('Default', 14), key='_NEW_ENTRY_')],
[sg.OK(), sg.Cancel()] ]
# Create the Window
window = sg.Window('My Diary', layout, size=(800,750))
# Event Loop to process "events" and get the "values" of the inputs
while True:
event, values = window.read()
if event == sg.WIN_CLOSED or event == 'Cancel': # if user closes window or clicks cancel
break
# here is where we put the logic to
# save the new entry into the json file
new_entry = values['_NEW_ENTRY_'] # entry[1] targets the 2nd multiline element
if new_entry != '\n' :
entry = Entry(new_entry)
diary.add_entry(entry)
# save
diary.save()
# update the gui to show the newwest entry as well
window.Element('_ENTRIES_').Update(value=diary.build_entries())
window.Element('_NEW_ENTRY_').Update(value='')
window.close()