-
Notifications
You must be signed in to change notification settings - Fork 0
/
project.py
66 lines (49 loc) · 2.12 KB
/
project.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
import tkinter
import tkinter.messagebox
import pickle
# klsadfhlds;hf
root = tkinter.Tk()
root.title("To-Do List")
def add_task():
task = entry_task.get()
if task != "":
listbox_tasks.insert(tkinter.END, task)
entry_task.delete(0, tkinter.END)
else:
tkinter.messagebox.showwarning(title="ATTENTION!", message="Please enter a task.")
def delete_task():
try:
task_index = listbox_tasks.curselection()[0]
listbox_tasks.delete(task_index)
except:
tkinter.messagebox.showwarning(title="ATTENTION!", message="Please select a task.")
def load_tasks():
try:
tasks = pickle.load(open("tasks.dat", "rb"))
listbox_tasks.delete(0, tkinter.END)
for task in tasks:
listbox_tasks.insert(tkinter.END, task)
except:
tkinter.messagebox.showwarning(title="ATTENTION!", message="Cannot find tasks.dat.")
def save_tasks():
tasks = listbox_tasks.get(0, listbox_tasks.size())
pickle.dump(tasks, open("tasks.dat", "wb"))
frame_tasks = tkinter.Frame(root)
frame_tasks.pack()
listbox_tasks = tkinter.Listbox(frame_tasks, height=20, width=50)
listbox_tasks.pack(side=tkinter.LEFT)
scrollbar_tasks = tkinter.Scrollbar(frame_tasks)
scrollbar_tasks.pack(side=tkinter.RIGHT, fill=tkinter.Y)
listbox_tasks.config(yscrollcommand=scrollbar_tasks.set)
scrollbar_tasks.config(command=listbox_tasks.yview)
entry_task = tkinter.Entry(root, width=60)
entry_task.pack()
button_add_task = tkinter.Button(root, text="Click to add task", font=("arial", 20,"bold"), background="brown", width=40, command=add_task)
button_add_task.pack()
button_delete_task = tkinter.Button(root, text="Click to delete task", font=("arial", 20,"bold"), background="pink", width=40, command=delete_task)
button_delete_task.pack()
button_load_tasks = tkinter.Button(root, text="Click to load task", font=("arial", 20,"bold"), background="grey", width=40, command=load_tasks)
button_load_tasks.pack()
button_save_tasks = tkinter.Button(root, text="Click to save task", font=("arial", 20,"bold"), background="green", width=40, command=save_tasks)
button_save_tasks.pack()
root.mainloop()