-
Notifications
You must be signed in to change notification settings - Fork 0
/
to_do.py
91 lines (71 loc) · 2.45 KB
/
to_do.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
import tkinter
from tkinter import *
root = Tk()
root.title("To-Do-List")
root.geometry("400x650+400+100")
root.resizable(False,False)
task_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)
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 taskfie:
for task in task_list:
taskfie.write(task+"\n")
listbox.delete(ANCHOR)
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()
# icon
Image_icon=PhotoImage(file="images/task.png")
root.iconphoto(False,Image_icon)
# top bar
TopImage =PhotoImage(file="images/topbar.png")
Label(root,image=TopImage).pack()
dockImage =PhotoImage(file="images/dock.png")
Label(root,image=dockImage,bg="#32405b").place(x=30,y=25)
noteImage = PhotoImage(file="images/task.png")
Label(root,image=noteImage,bg="#32405b").place(x=340,y=25)
heading = Label(root,text="ALL TASKS",font="arial 20 bold", fg="white",bg="#32405b")
heading.place(x=130,y=20)
# main
frame = Frame(root,width=400,height=50,bg="white")
frame.place(x=0,y=180)
task = StringVar()
task_entry= Entry(frame,width=18,font="arial 20",bd=0)
task_entry.place(x=10,y=7)
task_entry.focus()
button = Button(frame,text="ADD",font="arial 20 bold",width=6,bg="#5a95ff",fg="#fff",bd=0,command=addTask)
button.place(x=300,y=0)
# listbox
frame1 = Frame(root,bd=3,width=700,height=280,bg="#32405b")
frame1.pack(pady=(160,0))
listbox = Listbox(frame1,font=('arial',12),width=40,height=16,bg="#32405b",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)
openTaskfile()
#delete
Delete_icon = PhotoImage(file="images/delete.png")
Button(root,image=Delete_icon,bd=0,command=deleteTask).pack(side=BOTTOM,pady=13)
root.mainloop()