-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
251 lines (151 loc) · 6.07 KB
/
main.py
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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
import tkinter
from tkinter import *
from playsound import playsound
import pystray
from pystray import MenuItem as item
from PIL import Image, ImageTk
import tkinter.messagebox
import customtkinter
#window configuration
root=Tk()
root.title("To-Do-List")
root.geometry("400x650+400+100")
root.resizable(False, False)
root.configure(background = '#333333')
# Intialise the task list array
task_list = []
# pystray minimise to tray
# Define a function for quit the window
# This is for the system tray area
# This is referenced further down in the code
def quit_window(icon, item):
icon.stop()
root.destroy()
# Define a function to show the window again
# This is the system tray area
# This is referenced down further in the code
def show_window(icon, item):
icon.stop()
root.after(0,root.deiconify())
root.lift()
root.focus_force()
# Hide the window and show on the system taskbar
def hide_window():
root.withdraw()
image=Image.open("Image/task.png")
menu=(item('Show', show_window), item('Quit', quit_window))
icon=pystray.Icon("name", image, "My System Tray Icon", menu)
icon.run()
# destroys application, creates a system tray icon and is fed Quit, and Show when right clicked
def show_icon():
root.withdraw()
image=Image.open("Image/task.png")
menu=(item('Show', show_window), item('Quit', quit_window))
icon=pystray.Icon("name", image, "My System Tray Icon", menu)
icon.run()
# runs the show icon function, when windows application is closed
root.protocol('WM_DELETE_WINDOW', show_icon)
#function to add tasks to list
def addTask():
task = task_entry.get()
task_entry.delete(0, END)
if task:
with open("tasklist.txt", "a") as taskfile:
taskfile.write(f"\n{task}")
task_list.append(task)
listbox.insert( END, task)
# Play complete task SFX using playsound (windows compatible only)
def completetasksfx():
playsound('sfx/complete.mp3', False)
# Play sound when task ADD using playsound (windows compatible only)
def addtasksfx():
playsound('sfx/add.mp3', False)
#function to remove tasks from list
def deleteTask():
global task_list
task = str(listbox.get(ANCHOR))
if task in task_list:
task_list.remove(task)
with open("tasklist.txt", "w") as taskfile:
for task in task_list:
taskfile.write(task+"\n")
listbox.delete( ANCHOR)
#function to read the taskfile adn display the list of tasks
def openTaskFile():
try:
global task_list
with open("tasklist.txt", "r") as taskfile:
tasks = taskfile.readlines()
for task in tasks:
if task != "\n":
task_list.append(task)
listbox.insert(END, task)
except:
file = open("tasklist.txt", "w")
file.close()
# -------------------------------------------------------------------------------------------------
# UI
# image for application
Image_icon = PhotoImage(file="Image/task.png")
root.iconphoto(False, Image_icon)
# image for top bar
TopImage=PhotoImage(file="Image/topbar.png")
Label(root, image=TopImage, background = '#333333').pack()
# image for dock
dockImage=PhotoImage(file="Image/dock.png")
# image for tasks
noteImage = PhotoImage(file="image/task.png")
Label(root, image=noteImage, bg="#32405b").place(x=340, y=19)
heading = Label(root, text="To Do", font="arial 20 bold", fg="white", bg="#32405b")
heading.place(x=160, y=20)
# main
frame = Frame(root, width=400, height=50, bg="#252526")
frame.place(x=0, y=180)
task = StringVar()
task_entry = Entry(frame, width = 18, font="cascadia 20 ", bd=0, bg = '#464646', fg = 'white')
task_entry.place(x=10, y=7)
task_entry.focus()
button = Button(frame, text="ADD", font="Helvetica 20", width = 6, bg = "#1E1E1E", fg="#2F89FF", activebackground = '#2F89FF', activeforeground ='#FFFFFF', bd = 0, command= lambda:([addTask(), addtasksfx()]))
button.place(x = 300, y = 0)
# Enter button allows for same functionality as add button
root.bind("<Return>", lambda event: button.invoke([addTask(), addtasksfx()]))
#list box, scrollbar and frame
frame1 = Frame(root, bd=3, width = 700, height = 280, bg = "#333333")
frame1.pack(pady=(160, 0))
listbox = Listbox(frame1, font = ("gadugi", 12), width=40, height=16, bg="#1E1E1E", fg="white", cursor="hand2", selectbackground="#5a95ff")
listbox.pack(side=LEFT, fill = BOTH, padx=2)
scrollbar=Scrollbar(frame1)
scrollbar.pack(side = RIGHT, fill = BOTH)
listbox.config(yscrollcommand=scrollbar.set)
scrollbar.config(command=listbox.yview)
# Create a button, set the image, and set the background color to match the white box
button = tkinter.Button(root, text="Menu", image = dockImage, highlightbackground="#32405B", background="#32405B", borderwidth=0)
# Create a label to display the white box
label = tkinter.Label(root, text = "drop down", bg="#23262E", borderwidth=1)
# Define a function that animates the white box
def animate_box(event):
if label.winfo_ismapped():
label.place_forget()
else:
label.place(x=0, y=0, width=200, height=650)
label.lift()
# Bind the function to the button's click event, and set the event to "<Button-1>"
button.bind("<Button-1>", animate_box)
# Place the button in the top left corner of the screen
button.place(x=30, y=25)
# Create a delete button and set the sticky attribute to "ew"
delete_button = tkinter.Button(label, text="Delete", width = 200, height = 1)
# Define a function that deletes the label
def delete_label(event):
label.place_forget()
# Bind the delete function to the delete button's click event
delete_button.bind("<Button-1>", delete_label)
# Place the delete button on the label
delete_button.place(x=0, y=0)
# UI
# -------------------------------------------------------------------------------------------------
openTaskFile()
# delete, create as button
Delete_icon = PhotoImage(file="Image/delete.png")
Button(root, image = Delete_icon, fg = '#333333', bg = '#333333', activebackground = '#333333', bd = 0, command = lambda:[deleteTask(), completetasksfx()]).pack(side = BOTTOM, pady = 13)
root.mainloop()