Tech career with our top-tier training in Data Science, Software Testing, and Full Stack Development.
phone to 4Achievers +91-93117-65521 +91-801080-5667
Navigation Icons Navigation Icons Navigation Icons Navigation Icons Navigation Icons Navigation Icons Navigation Icons

+91-801080-5667
+91-801080-5667
Need Expert Advise, Enrol Free!!
Share this article

Python Simple TO-DO List App: A Beginner’s Guide to Building a Task Manager

Building a Simple To-Do List App with Pure Python: A Step-by-Step Guide for Beginners

Creating a Pure Python To-Do List App is an excellent beginner project that allows you to understand core Python concepts such as functions, loops, conditionals, and file handling. Here’s a step-by-step guide for students to build a simple To-Do List App using pure Python (without external libraries).

Project Overview

This app will allow users to:

  1. Add tasks.
  2. View tasks.
  3. Mark tasks as completed.
  4. Delete tasks.
  5. Save tasks to a text file so that they persist even after the app is closed.

Step 1: Set Up Your Python Environment

Ensure you have Python installed on your system. You can download it from python.org. Once installed, you can use any code editor like VS Code, PyCharm, or even IDLE (comes with Python installation).

Step 2: Define the Project Structure

In this simple project, we’ll use one Python file to manage everything. The tasks will be stored in a text file called tasks.txt to persist data even after the app is closed.

Project folder structure:
ToDoApp/
├── todo_app.py
└── tasks.txt
Step 3: Create Functions for the App

The app will be driven by several functions:

  1. Display the main menu.
  2. Add a task.
  3. View tasks.
  4. Mark a task as complete.
  5. Delete a task.
  6. Save tasks to a text file.

Load tasks from the text file.
Step 4: Write the Code

Here’s the code for the To-Do List app in pure Python:

import os

# Function to load tasks from the file
def load_tasks():
tasks = []
if os.path.exists("tasks.txt"):
with open("tasks.txt", "r") as file:
tasks = file.readlines()
return [task.strip() for task in tasks]

# Function to save tasks to the file
def save_tasks(tasks):
with open("tasks.txt", "w") as file:
for task in tasks:
file.write(task + "\n")

# Function to display the main menu
def display_menu():
print("\nTo-Do List App")
print("1. View Tasks")
print("2. Add Task")
print("3. Mark Task as Completed")
print("4. Delete Task")
print("5. Exit")
choice = input("Choose an option: ")
return choice

# Function to add a task
def add_task(tasks):
task = input("Enter the task: ")
tasks.append(task)
save_tasks(tasks)
print(f"Task '{task}' added successfully!")

# Function to view tasks
def view_tasks(tasks):
if not tasks:
print("No tasks available.")
else:
print("\nYour To-Do List:")
for index, task in enumerate(tasks):
print(f"{index + 1}. {task}")

# Function to mark a task as completed
def mark_task_completed(tasks):
view_tasks(tasks)
if tasks:
task_number = int(input("Enter task number to mark as completed: "))
if 1 <= task_number <= len(tasks):
tasks[task_number - 1] = tasks[task_number - 1] + " (Completed)"
save_tasks(tasks)
print("Task marked as completed!")
else:
print("Invalid task number!")

# Function to delete a task
def delete_task(tasks):
view_tasks(tasks)
if tasks:
task_number = int(input("Enter task number to delete: "))
if 1 <= task_number <= len(tasks):
task_to_delete = tasks.pop(task_number - 1)
save_tasks(tasks)
print(f"Task '{task_to_delete}' deleted successfully!")
else:
print("Invalid task number!")

# Main function to run the app
def main():
tasks = load_tasks()

while True:
choice = display_menu()

if choice == "1":
view_tasks(tasks)
elif choice == "2":
add_task(tasks)
elif choice == "3":
mark_task_completed(tasks)
elif choice == "4":
delete_task(tasks)
elif choice == "5":
print("Exiting the app. Goodbye!")
break
else:
print("Invalid choice. Please try again.")

if __name__ == "__main__":
main()

Step 5: Walkthrough of the Code

Loading and Saving Tasks:

  • load_tasks(): This function loads the tasks from the tasks.txt file into a list. If the file doesn't exist, it returns an empty list.
  • save_tasks(tasks): This function writes the current list of tasks back to the tasks.txt file, ensuring persistence.

Displaying Menu:

  • display_menu(): This function displays a simple text-based menu to the user and prompts them to choose an option.

Adding, Viewing, Marking, and Deleting Tasks:

  • add_task(tasks): Prompts the user for a task and adds it to the list.
  • view_tasks(tasks): Displays all tasks, including their current status (e.g., "Completed").
  • mark_task_completed(tasks): Lets the user mark a task as completed by appending "(Completed)" to it.
  • delete_task(tasks): Allows the user to delete a task from the list.

Main Loop:

  • The app runs in a loop where it continuously displays the menu, processes the user's input, and updates the task list accordingly.

Step 6: Running the App

  1. Save the above code in a Python file called todo_app.py inside your project folder.
  2. Open your terminal or command prompt.
  3. Navigate to the folder where your todo_app.py file is located.
  4. Run the Python script by typing:
  5. The app will prompt you with a menu to interact with.

python todo_app.py

The app will prompt you with a menu to interact with.

Step 7: Features and Enhancements

Once the basic app is working, you can enhance it with additional features:

  1. Sorting Tasks: Sort tasks by completion status or by priority.
  2. Priorities: Add the ability to set priorities (High, Medium, Low) for tasks.
  3. Task Categories: Allow users to categorize tasks (e.g., Work, Personal).
  4. Search Functionality: Implement a search feature to find tasks by keywords.
  5. Graphical User Interface (GUI): Use libraries like Tkinter or PyQt to create a graphical interface for your app.

Step 8: Conclusion

This project helps you get hands-on experience with basic Python programming and file handling. Once you complete the app, you’ll have a functional to-do list that saves your tasks between sessions, and you’ll have practiced core programming skills like loops, conditionals, file reading/writing, and handling user input.

Good luck building your To-Do List app!

Aaradhya, an M.Tech student, is deeply engaged in research, striving to push the boundaries of knowledge and innovation in their field. With a strong foundation in their discipline, Aaradhya conducts experiments, analyzes data, and collaborates with peers to develop new theories and solutions. Their affiliation with "4achievres" underscores their commitment to academic excellence and provides access to resources and mentorship, further enhancing their research experience. Aaradhya's dedication to advancing knowledge and making meaningful contributions exemplifies their passion for learning and their potential to drive positive change in their field and beyond.

Explore the latest job openings

Looking for more job opportunities? Look no further! Our platform offers a diverse array of job listings across various industries, from technology to healthcare, marketing to finance. Whether you're a seasoned professional or just starting your career journey, you'll find exciting opportunities that match your skills and interests. Explore our platform today and take the next step towards your dream job!

See All Jobs

Explore the latest blogs

Looking for insightful and engaging blogs packed with related information? Your search ends here! Dive into our collection of blogs covering a wide range of topics, from technology trends to lifestyle tips, finance advice to health hacks. Whether you're seeking expert advice, industry insights, or just some inspiration, our blog platform has something for everyone. Explore now and enrich your knowledge with our informative content!

See All Bogs

Enrolling in a course at 4Achievers will give you access to a community of 4,000+ other students.

Email

Our friendly team is here to help.
Info@4achievers.com

Phone

We assist You : Monday - Sunday (24*7)
+91-801080-5667
Register for Free Demo
By clicking the button above, you agree to our Terms of Use and Privacy Policy. We do not share this information.

Whatsapp

Call