-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
76 lines (63 loc) · 2.99 KB
/
Copy pathapp.py
File metadata and controls
76 lines (63 loc) · 2.99 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
71
72
73
74
75
76
import tkinter as tk
from tkinter import messagebox
class ToDoApp:
def __init__(self, root):
self.root = root
self.root.title("ToDo Application")
self.tasks = []
self.frame = tk.Frame(root)
self.frame.pack(pady=10)
self.task_entry = tk.Entry(self.frame, width=40)
self.task_entry.pack(side=tk.LEFT, padx=10)
# Add Task button with black border
self.add_button = tk.Button(self.frame, text="Add Task", font=("Arial Bold", 10), fg="red",
highlightbackground="black", highlightthickness=2, command=self.add_task)
self.add_button.pack(side=tk.LEFT)
self.task_listbox = tk.Listbox(root, width=50, height=10, selectmode=tk.SINGLE)
self.task_listbox.pack(pady=10)
# Create a frame to center the buttons
self.button_frame = tk.Frame(root)
self.button_frame.pack(pady=10)
# Mark as Completed button with black border
self.complete_button = tk.Button(self.button_frame, text="Mark as Completed", font=("Arial Bold", 10), fg="red",
highlightbackground="black", highlightthickness=2, command=self.mark_completed)
self.complete_button.pack(side=tk.LEFT, padx=10)
# Delete Task button with black border
self.delete_button = tk.Button(self.button_frame, text="Delete Task", font=("Arial Bold", 10), fg="red",
highlightbackground="black", highlightthickness=2, command=self.delete_task)
self.delete_button.pack(side=tk.LEFT)
def add_task(self):
task = self.task_entry.get()
if task:
self.tasks.append({"task": task, "completed": False})
self.update_listbox()
self.task_entry.delete(0, tk.END)
else:
messagebox.showwarning("Warning", "You must enter a task.")
def update_listbox(self):
self.task_listbox.delete(0, tk.END)
for task in self.tasks:
display_task = task["task"]
if task["completed"]:
display_task += " [Done]"
self.task_listbox.insert(tk.END, display_task)
def mark_completed(self):
selected_task_index = self.task_listbox.curselection()
if selected_task_index:
index = selected_task_index[0]
self.tasks[index]["completed"] = True
self.update_listbox()
else:
messagebox.showwarning("Warning", "You must select a task to mark as completed.")
def delete_task(self):
selected_task_index = self.task_listbox.curselection()
if selected_task_index:
index = selected_task_index[0]
del self.tasks[index]
self.update_listbox()
else:
messagebox.showwarning("Warning", "You must select a task to delete.")
if __name__ == "__main__":
root = tk.Tk()
app = ToDoApp(root)
root.mainloop()