-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGui.py
More file actions
70 lines (65 loc) · 2.78 KB
/
Copy pathGui.py
File metadata and controls
70 lines (65 loc) · 2.78 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
import PySimpleGUI as userInterface
import random
from functions import get_tasks, write_tasks, random_task
action_label = userInterface.Text("Type in a Task")
userinput = userInterface.InputText(tooltip="Enter Task", key="User")
add_button = userInterface.Button("Add")
list_of_tasks = userInterface.Listbox(values=get_tasks(), key="Tasks",size=(45,10), enable_events=True)
edit_button = userInterface.Button("Edit")
complete_button = userInterface.Button("Complete")
random_button = userInterface.Button("Random")
exit_button = userInterface.Button("Exit")
random_label = userInterface.Text("", key="random")
col = [[edit_button],[complete_button],[random_button]]
window = userInterface.Window("Task Manger", layout=[[action_label], [userinput,add_button], [list_of_tasks, userInterface.Column(col)], [exit_button, random_label]])
while True:
event, values = window.read()
print(event)
print(values)
print(values["Tasks"])
match event:
case "Add":
value_to_add = values["User"].replace("\n","") + "\n"
if(value_to_add.strip() == ""):
userInterface.popup("Please write an task", font=("Times New Roman", 10))
continue
print(value_to_add)
tasks = get_tasks()
tasks.append(value_to_add)
write_tasks(tasks)
window["Tasks"].update(values=tasks)
window["random"].update(value="")
case "Edit":
try:
value_to_edit = values["Tasks"][0]
tasks = get_tasks()
index = tasks.index(value_to_edit)
if(value_to_edit != values["User"]):
tasks[index] = values["User"] + "\n"
write_tasks(tasks)
print(tasks)
window["Tasks"].update(values=tasks)
window["random"].update(value="")
except IndexError:
userInterface.popup("Please select an task", font=("Times New Roman", 10))
case "Tasks":
window["User"].update(value=values['Tasks'][0])
case "Random":
task_right_now = random_task()
window["random"].update(value=f"Random task to complete: {task_right_now}")
case "Complete":
try:
value_to_complete = values["Tasks"][0]
tasks = get_tasks()
tasks.remove(value_to_complete)
write_tasks(tasks)
window["Tasks"].update(values=tasks)
window["User"].update(value="")
window["random"].update(value="")
except IndexError:
userInterface.popup("Please select an task", font=("Times New Roman", 10))
case "Exit":
break
case userInterface.WIN_CLOSED:
break
window.close()