Skip to content

Commit 5b6fdb0

Browse files
GUI ToDo List
1 parent fb78cd1 commit 5b6fdb0

File tree

1 file changed

+60
-0
lines changed

1 file changed

+60
-0
lines changed

gui.py

+60
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
import functions
2+
import PySimpleGUI as sg
3+
import time
4+
5+
6+
sg.theme("Black")
7+
clock = sg.Text('', key="clock")
8+
label = sg.Text("Type in a to-do")
9+
input_box = sg.InputText(tooltip="Enter todo", key="todo", size=[46,10])
10+
add = sg.Button("Add", size=10)
11+
list_box = sg.Listbox(values=functions.get_todos(), key="todos",
12+
enable_events=True, size=[45,9])
13+
edit = sg.Button("Edit", size=10)
14+
complete = sg.Button("Complete", size=10)
15+
exitButton = sg.Button("Exit", size=10)
16+
17+
window = sg.Window("My To-Do App",
18+
layout=[[clock], [label], [input_box, add], [list_box, edit, complete], [exitButton]],
19+
font=('Agency FB', 20))
20+
21+
while True:
22+
event, values = window.read(timeout=200)
23+
window["clock"].update(value=time.strftime("%b %d, %Y %H:%M:%S"))
24+
match event:
25+
case "Add":
26+
todos = functions.get_todos()
27+
new_todo = values['todo'] + "\n"
28+
todos.append(new_todo)
29+
functions.write_todos(todos)
30+
window['todos'].update(values=todos)
31+
case "Edit":
32+
try:
33+
todo_to_edit = values['todos'][0]
34+
new_todo = values['todo']
35+
todos = functions.get_todos()
36+
index = todos.index(todo_to_edit)
37+
todos[index] = new_todo
38+
functions.write_todos(todos)
39+
window['todos'].update(values=todos)
40+
except IndexError:
41+
sg.popup("Please select an item first.", font=("Helvetica", 20))
42+
case "Complete":
43+
try:
44+
todo_to_complete = values['todos'][0]
45+
todos = functions.get_todos()
46+
todos.remove(todo_to_complete)
47+
functions.write_todos(todos)
48+
window['todos'].update(values=todos)
49+
window['todo'].update(value=' ')
50+
except IndexError:
51+
sg.popup("Please select an item first.", font=("Helvetica", 20))
52+
case "Exit":
53+
break
54+
case 'todos':
55+
window['todo'].update(value=values['todos'][0])
56+
case sg.WIN_CLOSED:
57+
break
58+
59+
60+
window.close()

0 commit comments

Comments
 (0)