🔹 Introduction

The To-Do List App is one of the most popular beginner projects. It teaches you how to:
- Create a GUI with Tkinter.
- Use Listbox to display tasks.
- Add, delete, and mark tasks as done.
- Save tasks to a file so they persist after closing the app.
🔹 Code Example
import tkinter as tk
from tkinter import messagebox
# ------------------------------
# Functions
# ------------------------------
def add_task():
task = task_entry.get()
if task != "":
tasks_listbox.insert(tk.END, task)
task_entry.delete(0, tk.END)
else:
messagebox.showwarning("Warning", "Please enter a task!")
def delete_task():
try:
selected_task = tasks_listbox.curselection()[0]
tasks_listbox.delete(selected_task)
except:
messagebox.showwarning("Warning", "Please select a task to delete!")
def save_tasks():
tasks = tasks_listbox.get(0, tk.END)
with open("tasks.txt", "w") as f:
for task in tasks:
f.write(task + "\n")
messagebox.showinfo("Saved", "Tasks saved successfully!")
def load_tasks():
try:
with open("tasks.txt", "r") as f:
for task in f:
tasks_listbox.insert(tk.END, task.strip())
except FileNotFoundError:
pass
# ------------------------------
# GUI Setup
# ------------------------------
root = tk.Tk()
root.title("📝 To-Do List App")
root.geometry("400x500")
# Task entry
task_entry = tk.Entry(root, width=30, font=("Arial", 12))
task_entry.pack(pady=10)
# Add button
add_button = tk.Button(root, text="➕ Add Task", width=20, command=add_task)
add_button.pack(pady=5)
# Listbox
tasks_listbox = tk.Listbox(root, width=40, height=15, font=("Arial", 12))
tasks_listbox.pack(pady=10)
# Buttons
delete_button = tk.Button(root, text="❌ Delete Task", width=20, command=delete_task)
delete_button.pack(pady=5)
save_button = tk.Button(root, text="💾 Save Tasks", width=20, command=save_tasks)
save_button.pack(pady=5)
# Load tasks at startup
load_tasks()
root.mainloop()
🔹 Features of This App
- Add Task ➝ Write in the input box and click Add Task.
- Delete Task ➝ Select a task in the list and click Delete Task.
- Save Tasks ➝ Saves all tasks into a file (
tasks.txt
). - Auto Load ➝ When you restart the app, it automatically loads tasks from
tasks.txt
.
🔹 Example Run
- User types “Study Python”, clicks Add Task → Task appears in the list.
- User selects the task “Study Python”, clicks Delete Task → Task removed.
- User clicks Save Tasks → All tasks saved to file.
🔹 Summary
- Learned how to build a To-Do List App with Tkinter.
- Practiced listbox, buttons, entry widgets.
- Learned how to save and load data from a file.