NoCostHub

Everything You Needs

How to Build a To-Do App in Python in 30 Minutes (Step-by-Step Guide)

python

If you’re learning Python, building small projects is the best way to improve your skills. One of the easiest and most useful beginner projects is a To-Do List Application. In this tutorial, we’ll show you how to build a fully functional To-Do App in Python in just 30 minutes no complex frameworks, just simple code you can understand.

Why Build a To-Do App?

A to-do app is perfect for beginners because:

  • It teaches you basic Python syntax.
  • You learn file handling to store data.
  • You practice loops, functions, and lists.
  • You can extend it later with GUI (Tkinter) or databases.

Requirements

Before we start, make sure you have:

  • Python 3.x installed
  • A text editor like VS Code or PyCharm
  • Basic knowledge of Python syntax

Step 1: Create the Project File

Create a new Python file called:

todo.py

Step 2: Write the Basic Structure

We’ll store tasks in a list and allow the user to:

  1. Add tasks
  2. View tasks
  3. Delete tasks
  4. Exit the program

Here’s the starter code:

tasks = []

def show_menu():
    print("\nTo-Do App")
    print("1. View Tasks")
    print("2. Add Task")
    print("3. Delete Task")
    print("4. Exit")

while True:
    show_menu()
    choice = input("Enter your choice: ")

    if choice == "1":
        if not tasks:
            print("No tasks yet!")
        else:
            print("\nYour Tasks:")
            for i, task in enumerate(tasks, start=1):
                print(f"{i}. {task}")

    elif choice == "2":
        task = input("Enter a new task: ")
        tasks.append(task)
        print("Task added!")

    elif choice == "3":
        if not tasks:
            print("No tasks to delete!")
        else:
            for i, task in enumerate(tasks, start=1):
                print(f"{i}. {task}")
            try:
                task_num = int(input("Enter task number to delete: "))
                if 1 <= task_num <= len(tasks):
                    removed = tasks.pop(task_num - 1)
                    print(f"Deleted: {removed}")
                else:
                    print("Invalid task number!")
            except ValueError:
                print("Please enter a valid number!")

    elif choice == "4":
        print("Goodbye!")
        break

    else:
        print("Invalid choice! Please try again.")

Step 3: Run the App

Open your terminal and run:

python todo.py

Step 4: Saving Tasks (Optional Upgrade)

To make your app more useful, you can store tasks in a file so they aren’t lost when you close the program.

Add these functions before the main loop:

import os

FILE_NAME = "tasks.txt"

def load_tasks():
    if os.path.exists(FILE_NAME):
        with open(FILE_NAME, "r") as file:
            return [line.strip() for line in file.readlines()]
    return []

def save_tasks():
    with open(FILE_NAME, "w") as file:
        for task in tasks:
            file.write(task + "\n")

tasks = load_tasks()

And after adding or deleting a task, call:

save_tasks()

Possible Improvements

Once you’ve mastered the basics, you can:

  • Create a GUI version using Tkinter.
  • Add a due date feature.
  • Use SQLite database instead of text files.
  • Turn it into a web app using Django or Flask.

Conclusion

You just learned how to build a To-Do App in Python in 30 minutes. This simple project covers the fundamentals of Python programming lists, loops, functions, and file handling. Keep experimenting and adding features to make it your own!

Comments

One response to “How to Build a To-Do App in Python in 30 Minutes (Step-by-Step Guide)”

  1. […] don’t need to be an expert to make something useful and fun. In fact, there are plenty of simple Python projects you can finish in under 1 […]

Leave a Reply

Your email address will not be published. Required fields are marked *