-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTo-Do-List.py
72 lines (56 loc) · 2.13 KB
/
To-Do-List.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
from tkinter import *
from tkinter import messagebox
# Function to add a task to the Listbox
def add_task():
task = entry_task.get()
if task != "":
listbox_tasks.insert(END, task)
entry_task.delete(0, "end")
else:
messagebox.showwarning("Warning", "You must enter a task.")
# Function to delete a selected task from the Listbox
def delete_task():
try:
selected_task_index = listbox_tasks.curselection()[0]
listbox_tasks.delete(selected_task_index)
except:
messagebox.showwarning("Warning", "You must select a task.")
# Function to mark a task as completed
def mark_completed():
try:
selected_task_index = listbox_tasks.curselection()[0]
task = listbox_tasks.get(selected_task_index)
listbox_tasks.delete(selected_task_index)
listbox_tasks.insert(END, task + " - Completed")
except:
messagebox.showwarning("Warning", "You must select a task.")
# Create the main window
window = Tk()
window.title("To-Do List")
# Create a Frame for the Listbox and Scrollbar
frame_tasks = Frame(window)
frame_tasks.pack()
# Create a Listbox
listbox_tasks = Listbox(
frame_tasks, bg="black", fg="white", height=15, width=50, font="helvetica"
)
listbox_tasks.pack(side=LEFT)
# Create a Scrollbar and attach it to the Listbox
scrollbar_tasks = Scrollbar(frame_tasks)
scrollbar_tasks.pack(side=RIGHT, fill=Y)
listbox_tasks.config(yscrollcommand=scrollbar_tasks.set)
scrollbar_tasks.config(command=listbox_tasks.yview)
# Create an Entry widget for new tasks
entry_task = Entry(window, width=50)
entry_task.pack(pady=10)
# Create Buttons for adding, deleting, and marking tasks as completed
button_add_task = Button(window, text="Add Task", width=20, command=add_task)
button_add_task.pack(pady=5)
button_delete_task = Button(window, text="Delete Task", width=20, command=delete_task)
button_delete_task.pack(pady=5)
button_mark_completed = Button(
window, text="Mark as Completed", width=20, command=mark_completed
)
button_mark_completed.pack(pady=5)
# Run the main loop
window.mainloop()