-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgui.py
More file actions
79 lines (66 loc) · 2.61 KB
/
gui.py
File metadata and controls
79 lines (66 loc) · 2.61 KB
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
import functions
import PySimpleGUI as py
import time
import os
if not os.path.exists("todos_item.txt"):
with open("todos_item.txt", 'w') as file:
pass
py.theme("DarkTeal4")
clock = py.Text(' ', key='clock')
label = py.Text("Type in a to-do")
input_box = py.InputText(tooltip="Enter to-do", key="todo")
add_button = py.Button(size=10, image_source="add.png", mouseover_colors="LightBlue2",
tooltip="Add Todo", key="Add")
# noinspection PyTypeChecker
list_box = py.Listbox(values=functions.get_todos(), key='todos',
enable_events=True, size=[45, 10])
edit_button = py.Button("Edit")
complete_button = py.Button(size=10, image_source="complete.png", mouseover_colors="LightBlue2",
tooltip="Complete Todo", key="Complete")
exit_button = py.Button("Exit")
button_labels = ["Close", "Apply"]
window = py.Window('My TO-DO App',
layout=[[clock],
[label], [input_box, add_button],
[list_box, edit_button, complete_button],
[exit_button]],
font=('Helvetica', 10))
while True:
event, values = window.read(timeout=10)
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]
new_todo = values['todo'] + '\n'
todos = functions.get_todos()
index = todos.index(todo_to_edit)
todos[index] = new_todo
functions.write_todos(todos)
window['todos'].update(values=todos)
except IndexError:
py.popup("Please select an item first. ", font=('Helvetica', 10))
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:
py.popup("Please select an item first. ", font=('Helvetica', 10))
case "Exit":
break
case 'todos':
window['todo'].update(value=values['todos'])
case py.WIN_CLOSED:
break
print("Bye")
window.close()