-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgui.py
More file actions
65 lines (60 loc) · 2.31 KB
/
gui.py
File metadata and controls
65 lines (60 loc) · 2.31 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
import functions
import FreeSimpleGUI as gui
import time
now = time.strftime("%b %d %Y %H:%M:%S")
clock = gui.Text('', key = "Clock")
label = gui.Text("Type in a to-do:")
input_box = gui.InputText(tooltip="Enter to-do", key="todo")
add_button = gui.Button("Add")
list_box = gui.Listbox(values= functions.get_todos(), key="todos",
enable_events="True", size=[45,10])
edit_button = gui.Button("Edit")
complete_button = gui.Button("Complete")
exit_button = gui.Button("Exit")
window=gui.Window('My to-do App',
layout=[[clock],
[label],
[input_box,add_button],
[list_box,edit_button,complete_button],
[exit_button]],
font=("Helvetica",20))
while True:
event,value = window.read()
window["Clock"].update(value = time.strftime("%b %d %Y %H:%M:%S"))
#print(event)
#print(1,value)
match event:
case "Add":
todos = functions.get_todos()
new_todo = value["todo"] + "\n"
todos.append(new_todo)
functions.write_todos(todos)
window['todos'].update(values= todos)
case "Edit":
try:
todo_to_edit = value["todos"][0]
new_todo = value["todo"]
todo = functions.get_todos()
index = todo.index(todo_to_edit)
todo[index] = new_todo
functions.write_todos(todo)
window['todos'].update(values= todo)
except IndexError:
gui.popup("Select an Item First.",font=("Helvetica",20))
case "todos":
window['todo'].update(value= value['todos'][0])
case "Complete":
try:
todos = functions.get_todos()
completed_todo = value["todo"]
todos.remove(completed_todo)
functions.write_todos(todos)
window['todos'].update(values= todos)
window['todo'].update(value = "")
except ValueError:
gui.popup("Select an Item First.",font=("Helvetica",20))
case "Exit":
exit()
case gui.WIN_CLOSED:
break
window.close()