-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTO-DO LIST
57 lines (45 loc) · 1.88 KB
/
TO-DO LIST
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
import tkinter as tk
from tkinter import messagebox
class ToDoListApp:
def __init__(self, master):
self.master = master
self.master.title("To-Do List App")
self.tasks = []
self.task_var = tk.StringVar()
# Entry for adding tasks
self.task_entry = tk.Entry(master, textvariable=self.task_var, width=30)
self.task_entry.grid(row=0, column=0, padx=10, pady=10)
# Buttons for actions
self.add_button = tk.Button(master, text="Add Task", command=self.add_task)
self.add_button.grid(row=0, column=1, padx=5)
self.remove_button = tk.Button(master, text="Remove Task", command=self.remove_task)
self.remove_button.grid(row=1, column=1, pady=5)
# Listbox for displaying tasks
self.task_listbox = tk.Listbox(master, selectmode=tk.SINGLE, width=40, height=10)
self.task_listbox.grid(row=2, column=0, columnspan=2, padx=10, pady=10)
# Populate initial tasks
self.update_task_listbox()
def add_task(self):
task = self.task_var.get()
if task:
self.tasks.append(task)
self.update_task_listbox()
self.task_var.set("") # Clear the entry
else:
messagebox.showwarning("Warning", "Please enter a task.")
def remove_task(self):
selected_index = self.task_listbox.curselection()
if selected_index:
selected_task = self.task_listbox.get(selected_index[0])
self.tasks.remove(selected_task)
self.update_task_listbox()
else:
messagebox.showwarning("Warning", "Please select a task to remove.")
def update_task_listbox(self):
self.task_listbox.delete(0, tk.END)
for task in self.tasks:
self.task_listbox.insert(tk.END, task)
if __name__ == "__main__":
root = tk.Tk()
app = ToDoListApp(root)
root.mainloop()