-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtask 1
99 lines (84 loc) · 3.11 KB
/
task 1
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
import tkinter as tk
from tkinter import messagebox
class TodoApp:
def __init__(self, root):
self.root = root
self.root.title("To-Do List")
self.tasks = []
self.task_frame = tk.Frame(self.root)
self.task_frame.pack(pady=10)
self.task_listbox = tk.Listbox(
self.task_frame,
width=50,
height=10,
selectmode=tk.SINGLE
)
self.task_listbox.pack(side=tk.LEFT, fill=tk.BOTH)
self.scrollbar = tk.Scrollbar(
self.task_frame,
orient=tk.VERTICAL,
command=self.task_listbox.yview
)
self.scrollbar.pack(side=tk.RIGHT, fill=tk.Y)
self.task_listbox.config(yscrollcommand=self.scrollbar.set)
self.entry_frame = tk.Frame(self.root)
self.entry_frame.pack(pady=10)
self.task_entry = tk.Entry(self.entry_frame, width=40)
self.task_entry.pack(side=tk.LEFT, padx=10)
self.add_button = tk.Button(
self.entry_frame,
text="Add Task",
width=10,
bg="green",
fg="white",
command=self.add_task
)
self.add_button.pack(side=tk.LEFT)
self.button_frame = tk.Frame(self.root)
self.button_frame.pack(pady=10)
self.delete_button = tk.Button(
self.button_frame,
text="Delete Task",
width=10,
bg="red",
fg="white",
command=self.delete_task
)
self.delete_button.pack(side=tk.LEFT, padx=10)
self.mark_button = tk.Button(
self.button_frame,
text="Mark Completed",
width=15,
command=self.mark_completed
)
self.mark_button.pack(side=tk.LEFT, padx=10)
def add_task(self):
task = self.task_entry.get()
if task != "":
self.tasks.append(task)
self.task_listbox.insert(tk.END, task)
self.task_entry.delete(0, tk.END)
else:
messagebox.showwarning("Warning", "You must enter a task.")
def delete_task(self):
selected_task_index = self.task_listbox.curselection()
if selected_task_index:
task_index = selected_task_index[0]
self.task_listbox.delete(task_index)
del self.tasks[task_index]
else:
messagebox.showwarning("Warning", "You must select a task to delete.")
def mark_completed(self):
selected_task_index = self.task_listbox.curselection()
if selected_task_index:
task_index = selected_task_index[0]
task = self.tasks[task_index]
self.tasks[task_index] = f"{task} (Completed)"
self.task_listbox.delete(task_index)
self.task_listbox.insert(task_index, self.tasks[task_index])
else:
messagebox.showwarning("Warning", "You must select a task to mark as completed.")
if __name__ == "__main__":
root = tk.Tk()
app = TodoApp(root)
root.mainloop()