-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathA_to_do_list (project) .py
More file actions
57 lines (45 loc) · 1.73 KB
/
A_to_do_list (project) .py
File metadata and controls
57 lines (45 loc) · 1.73 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
import tkinter as tk
from tkinter import messagebox
# Create main window
root = tk.Tk()
root.title("My To-Do List")
root.geometry("400x450")
root.config(bg="#f4f4f4")
# Heading
heading = tk.Label(root, text="My Daily Tasks", font=("Arial", 18, "bold"), bg="#f4f4f4", fg="#333")
heading.pack(pady=10)
# Entry field
task_entry = tk.Entry(root, font=("Arial", 14), width=30)
task_entry.pack(pady=10)
# Frame for buttons
btn_frame = tk.Frame(root, bg="#f4f4f4")
btn_frame.pack(pady=5)
# Listbox to show tasks
task_listbox = tk.Listbox(root, font=("Arial", 12), width=40, height=10, selectbackground="#a3d2ca")
task_listbox.pack(pady=10)
# Functions
def add_task():
task = task_entry.get().strip()
if task:
task_listbox.insert(tk.END, task)
task_entry.delete(0, tk.END)
else:
messagebox.showwarning("Empty Field", "Please enter a task.")
def delete_task():
selected = task_listbox.curselection()
if selected:
task_listbox.delete(selected)
else:
messagebox.showwarning("No Selection", "Please select a task to delete.")
def clear_all():
if messagebox.askyesno("Clear All", "Are you sure you want to delete all tasks?"):
task_listbox.delete(0, tk.END)
# Buttons
add_btn = tk.Button(btn_frame, text="Add Task", font=("Arial", 12), bg="#76b5c5", fg="white", width=10, command=add_task)
add_btn.grid(row=0, column=0, padx=5)
del_btn = tk.Button(btn_frame, text="Delete Task", font=("Arial", 12), bg="#e27d60", fg="white", width=12, command=delete_task)
del_btn.grid(row=0, column=1, padx=5)
clear_btn = tk.Button(btn_frame, text="Clear All", font=("Arial", 12), bg="#c94c4c", fg="white", width=10, command=clear_all)
clear_btn.grid(row=0, column=2, padx=5)
# Run the app
root.mainloop()