The Palos Publishing Company

Follow Us On The X Platform @PalosPublishing
Categories We Write About

Build a Python-based to-do list app

Here’s a basic Python-based To-Do List App using the tkinter library for a simple GUI interface. This app allows users to add, delete, and save tasks.

python
import tkinter as tk from tkinter import messagebox import os TASKS_FILE = "tasks.txt" class ToDoApp: def __init__(self, root): self.root = root self.root.title("To-Do List App") self.root.geometry("400x450") self.root.configure(bg="#f0f0f0") self.tasks = [] self.title = tk.Label(root, text="My To-Do List", font=("Helvetica", 18, "bold"), bg="#f0f0f0") self.title.pack(pady=10) self.task_entry = tk.Entry(root, font=("Helvetica", 14), width=30) self.task_entry.pack(pady=10) self.add_btn = tk.Button(root, text="Add Task", font=("Helvetica", 12), width=15, command=self.add_task) self.add_btn.pack(pady=5) self.task_listbox = tk.Listbox(root, font=("Helvetica", 14), width=35, height=10, selectbackground="lightblue") self.task_listbox.pack(pady=10) self.del_btn = tk.Button(root, text="Delete Selected", font=("Helvetica", 12), width=15, command=self.delete_task) self.del_btn.pack(pady=5) self.save_btn = tk.Button(root, text="Save Tasks", font=("Helvetica", 12), width=15, command=self.save_tasks) self.save_btn.pack(pady=5) self.load_tasks() def add_task(self): task = self.task_entry.get().strip() if task: self.tasks.append(task) self.update_listbox() self.task_entry.delete(0, tk.END) else: messagebox.showwarning("Warning", "Task cannot be empty") def delete_task(self): selected = self.task_listbox.curselection() if selected: index = selected[0] self.tasks.pop(index) self.update_listbox() else: messagebox.showwarning("Warning", "No task selected") def update_listbox(self): self.task_listbox.delete(0, tk.END) for task in self.tasks: self.task_listbox.insert(tk.END, task) def save_tasks(self): with open(TASKS_FILE, "w") as f: for task in self.tasks: f.write(task + "n") messagebox.showinfo("Saved", "Tasks saved successfully!") def load_tasks(self): if os.path.exists(TASKS_FILE): with open(TASKS_FILE, "r") as f: self.tasks = [line.strip() for line in f.readlines()] self.update_listbox() if __name__ == "__main__": root = tk.Tk() app = ToDoApp(root) root.mainloop()

Features:

  • Add a task.

  • Delete selected task.

  • Save tasks to a file (tasks.txt).

  • Load saved tasks on startup.

Requirements:

  • Works out of the box with Python 3.

  • No external packages required.

Let me know if you want an advanced version with categories, priorities, or due dates.

Share this Page your favorite way: Click any app below to share.

Enter your email below to join The Palos Publishing Company Email List

We respect your email privacy

Categories We Write About