-
Notifications
You must be signed in to change notification settings - Fork 0
/
gui.py
65 lines (59 loc) · 2.27 KB
/
gui.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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import functions
import FreeSimpleGUI as sg
import time
sg.theme('LightBrown6')
label_clock = sg.Text('', key='clock')
label = sg.Text('Type in the new item')
input_box = sg.InputText(tooltip='Enter a todo', key='todo',
size=[41])
add_button = sg.Button("Add")
list_box = sg.Listbox(values=functions.get_todos(), key='todos',
enable_events=True, size=[40, 8])
edit_button = sg.Button("Edit")
complete_button = sg.Button("Complete")
exit_button = sg.Button("Exit")
window = sg.Window('To-do App',
layout=[[label_clock],
[label],
[input_box, add_button],
[list_box, edit_button, complete_button],
[exit_button]],
font=('Helvetica', 15))
while True:
event, values = window.read(timeout=500)
window['clock'].update(value=time.strftime("%b %d, %Y %H:%M:%S"))
match event:
case 'Add':
todos = functions.get_todos()
new_todo = values['todo'] + '\n'
todos.append(new_todo)
functions.write_todos(todos)
window['todos'].update(values=todos)
case 'Edit':
try:
todo_to_edit = values['todos'][0]
todos = functions.get_todos()
index = todos.index(todo_to_edit)
new_todo = values['todo'] + '\n'
todos[index] = new_todo
functions.write_todos(todos)
window['todos'].update(values=todos)
except IndexError:
sg.popup("Please select a todo to Edit.", font=('Helvetica', 15))
case 'Complete':
try:
todo_to_complete = values['todos'][0]
todos = functions.get_todos()
todos.remove(todo_to_complete)
functions.write_todos(todos)
window['todos'].update(values=todos)
window['todo'].update(value='')
except IndexError:
sg.popup('please select a todo to complete.', font=('Helvetica', 15))
case 'todos':
window['todo'].update(value=values['todos'][0])
case 'Exit':
break
case sg.WIN_CLOSED:
break
window.close()