This repository was archived by the owner on Oct 20, 2026. It is now read-only.
Repository navigation
Expand file tree
/
Copy pathMain_18_Superior_ToEXE.py
More file actions
134 lines (101 loc) · 4.72 KB
/
Copy pathMain_18_Superior_ToEXE.py
File metadata and controls
134 lines (101 loc) · 4.72 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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
import os
import time
from time import strftime
import PySimpleGUI as sg
from Modules.Functions_Day16_GUI import ord, get_save, write_save
if not os.path.exists("todos.txt"):
with open("todos.txt", "w") as file:
pass
sg.theme("DarkBrown1")
daymonth = time.strftime("%A, %B ")
date = ord(int(time.strftime("%d")))
dayofyear = ord(int(time.strftime("%j")))
time = time.strftime("%I:%M:%S %p")
datetimegreeting = sg.Text(
f"Hello! The current date is {daymonth}{date}.\nThe time at which you opened this program was {time}.\n"
f"It is the {dayofyear} day of the year.", text_color="LemonChiffon4", justification="left")
clock = sg.Text("", key="clock")
hello = sg.Text("Welcome to your To-Do List.", justification="center")
input_text = sg.Text("New To-Do Item:")
input_box = sg.InputText(tooltip="Enter input here:", key="TODO", size=29)
buttontext = ("Garamond", 16)
add_button = sg.Button("Add Item", key="add", mouseover_colors="dark orange", font=buttontext)
list_box = sg.Listbox(values=get_save(), enable_events=True, size=[45, 10],
key = "todos")
edit_button = sg.Button("Edit a To-Do Item", key="edit", mouseover_colors="dark orange",
font=buttontext, size=19)
complete_button = sg.Button("Complete a To-Do Item",
key="complete", mouseover_colors="dark orange",
font=buttontext, size=19)
exit_button = sg.Button("Exit program", key="exit", mouseover_colors="dark orange",
font=buttontext, size = 20)
buttoncol = [[sg.Text("For Existing To-Do Items:")], [edit_button], [complete_button]]
window = sg.Window("Bryan's Python To-Do App",
layout=[[datetimegreeting], [clock], [hello],
[input_text, input_box, add_button],
[list_box, sg.Column(buttoncol, element_justification="center")],
[exit_button]],
font=("Garamond", 18))
while True:
event, values = window.read(timeout=400)
# print(f"Event is {event}") # Gets the label of the button that was pressed
# print(f"values is {values}") # Gets the actual input to the field associated with that button.
# print(f"values['todos'] is {values['todos']}")
window["clock"].update(value=f"The current time is: {strftime('%b %d, %Y %I:%M:%S %p')}.")
match event:
case "add":
todos = get_save()
new_todo = values["TODO"] + "\n"
todos.append(new_todo)
write_save(todos)
window["todos"].update(values=todos)
window["TODO"].update(value="")
case "edit":
try:
todo_to_edit = values["todos"][0]
# Create a pop-up window for editing
edit_layout = [
[sg.Text("Please select what you'd like to change this To-Do to be.")],
[sg.Input(key="edit_input")],
[sg.Button("Edit", key="edit_confirm")]
]
edit_window = sg.Window("Edit To-Do", layout=edit_layout)
while True:
edit_event, edit_values = edit_window.read()
if edit_event == "edit_confirm":
new_todo = edit_values["edit_input"] + "\n"
todos = get_save()
index = todos.index(todo_to_edit)
todos[index] = new_todo
write_save(todos)
window["todos"].update(values=todos)
edit_window.close()
break
elif edit_event == sg.WINDOW_CLOSED:
break
except IndexError:
sg.popup("Please select an item to edit before clicking the Edit button.", no_titlebar=True,
font=("Garamond", 14))
case "todos":
window["TODO"].update(value=values["todos"][0])
case "complete":
try:
todo_to_complete = values["todos"][0]
todos = get_save()
todos.remove(todo_to_complete)
write_save(todos)
window["todos"].update(values=todos)
window["TODO"].update(value="")
except IndexError:
sg.popup("Please select an item to complete before clicking the Complete button.", no_titlebar=True,
font=("Garamond", 14))
# case "TODO":
# if window["TODO"].get() == "Enter input here:":
# window["TODO"].update(value="")
case ("exit"):
break
case sg.WINDOW_CLOSED:
break
exit()
print("Bye!")
window.close()