-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlatesttodolist.py
66 lines (50 loc) · 2.35 KB
/
latesttodolist.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 as tk
from tkinter import messagebox
class ToDoApp:
def __init__(self, root):
self.root = root
self.root.title("Ujwal's To-Do List 💖")
self.root.geometry("400x400")
self.root.resizable(False, False)
self.tasks = []
self.title_label = tk.Label(self.root, text="My To-Do List", font=("Helvetica", 18, "bold"), fg="#ff69b4")
self.title_label.pack(pady=10)
self.frame = tk.Frame(self.root)
self.frame.pack(pady=10)
self.task_listbox = tk.Listbox(self.frame, width=30, height=10, bd=0, font=("Helvetica", 12))
self.task_listbox.pack(side=tk.LEFT, fill=tk.BOTH)
self.scrollbar = tk.Scrollbar(self.frame)
self.scrollbar.pack(side=tk.RIGHT, fill=tk.BOTH)
self.task_listbox.config(yscrollcommand=self.scrollbar.set)
self.scrollbar.config(command=self.task_listbox.yview)
self.entry_frame = tk.Frame(self.root)
self.entry_frame.pack(pady=10)
self.entry = tk.Entry(self.entry_frame, width=30, font=("Helvetica", 12))
self.entry.pack(side=tk.LEFT, padx=10)
self.add_button = tk.Button(self.entry_frame, text="Add Task", command=self.add_task, bg="#ff69b4", fg="white", font=("Helvetica", 12))
self.add_button.pack(pady=10)
self.delete_button = tk.Button(self.root, text="Delete Task", command=self.delete_task, bg="red", fg="white", font=("Helvetica", 12))
self.delete_button.pack(pady=10)
self.populate_listbox()
def populate_listbox(self):
for task in self.tasks:
self.task_listbox.insert(tk.END, task)
def add_task(self):
task = self.entry.get()
if task != "":
self.tasks.append(task)
self.task_listbox.insert(tk.END, task)
self.entry.delete(0, tk.END)
else:
messagebox.showwarning("Warning", "You must enter a task.")
def delete_task(self):
try:
task_index = self.task_listbox.curselection()[0]
self.task_listbox.delete(task_index)
del self.tasks[task_index]
except IndexError:
messagebox.showwarning("Warning", "You must select a task to delete.")
if __name__ == "__main__":
root = tk.Tk()
app = ToDoApp(root)
root.mainloop()