Python Project with Source Code: to-do list application

To-Do List App Using Python

Introduction

Python, the powerful, easy-to-learn, high-level programming language, is renowned for its simplicity and readability. With a list of applications from web development to data analysis, machine learning, and more, Python is a must-have in your developer toolkit. Today, we’re going to walk you through a simple yet insightful Python project – creating a GUI Based to-do list application. This Python project will help you to understand Python while giving you hands-on experience in creating a GUI(Graphical user interface) application.

Project Requirements

Before diving into the source code, make sure you have the following:

  1. Python: The project is coded in Python 3. Ensure you have Python 3 and Pip installed on your computer. If not, you can download it from the official Python website.
  2. Text Editor: Any text editor or Integrated Development Environment (IDE) you are comfortable with, such as Sublime Text(my personal favorite), Visual Studio Code, or PyCharm.

Python project – creating a GUI Based to-do list application

Our Python to-do list application will include the ability to add tasks, view tasks, and delete tasks.

Source Code

A Graphical User Interface (GUI) for our Python To-Do List project. We will use Tkinter, Python’s standard GUI library, which is included in the standard Python installation.


from tkinter import *
from tkinter import messagebox
from tkinter import ttk

class SexyToDoList:
    def __init__(self, root):
        self.root = root
        self.root.title("🔥 Ultra-Sexy To-Do List")
        self.root.geometry("420x550")
        self.root.configure(bg="#1f1f2e")
        self.root.resizable(False, False)

        self.tasks = []

        style = ttk.Style()
        style.theme_use("clam")
        style.configure("TButton",
                        font=("Segoe UI", 12),
                        foreground="#ffffff",
                        background="#6c5ce7",
                        borderwidth=0)
        style.map("TButton",
                  background=[('active', '#5e50d4')],
                  relief=[('pressed', 'sunken')])

        style.configure("TEntry",
                        font=("Segoe UI", 12),
                        padding=10)

        self.title_label = Label(self.root, text="✨ My To-Do List", font=("Segoe UI Semibold", 20), bg="#1f1f2e", fg="white")
        self.title_label.pack(pady=(30, 10))

        self.entry_frame = Frame(self.root, bg="#1f1f2e")
        self.entry_frame.pack(pady=10)

        self.task_entry = ttk.Entry(self.entry_frame, width=26)
        self.task_entry.pack(side=LEFT, padx=(0, 10))
        self.task_entry.bind('<Return>', lambda event: self.add_task())

        self.add_button = ttk.Button(self.entry_frame, text="Add", command=self.add_task)
        self.add_button.pack(side=LEFT)

        self.task_frame = Frame(self.root, bg="#1f1f2e")
        self.task_frame.pack(pady=20)

        self.scrollbar = Scrollbar(self.task_frame, orient=VERTICAL)

        self.task_listbox = Listbox(
            self.task_frame,
            width=40,
            height=12,
            font=("Segoe UI", 12),
            bg="#2a2a3d",
            fg="white",
            bd=0,
            highlightthickness=0,
            selectbackground="#6c5ce7",
            yscrollcommand=self.scrollbar.set,
            activestyle='none'
        )

        self.scrollbar.config(command=self.task_listbox.yview)
        self.scrollbar.pack(side=RIGHT, fill=Y)
        self.task_listbox.pack(side=LEFT, fill=BOTH)

        self.button_frame = Frame(self.root, bg="#1f1f2e")
        self.button_frame.pack(pady=25)

        self.delete_button = ttk.Button(self.button_frame, text="🗑 Delete Selected", command=self.delete_task)
        self.delete_button.grid(row=0, column=0, padx=10, pady=5)

        self.clear_button = ttk.Button(self.button_frame, text="🚫 Clear All", command=self.clear_tasks)
        self.clear_button.grid(row=0, column=1, padx=10, pady=5)

        self.footer = Label(self.root, text="Made with ❤️ by You", font=("Segoe UI", 10), bg="#1f1f2e", fg="#888")
        self.footer.pack(side=BOTTOM, pady=10)

        self.load_tasks()

    def add_task(self):
        task = self.task_entry.get().strip()
        if task:
            self.task_listbox.insert(END, task)
            self.tasks.append(task)
            self.task_entry.delete(0, END)
            self.save_tasks()
        else:
            messagebox.showinfo("Oops!", "Please enter a task.")

    def delete_task(self):
        try:
            index = self.task_listbox.curselection()[0]
            self.task_listbox.delete(index)
            self.tasks.pop(index)
            self.save_tasks()
        except IndexError:
            messagebox.showwarning("No Selection", "Please select a task to delete.")

    def clear_tasks(self):
        if messagebox.askyesno("Confirm", "Delete all tasks?"):
            self.task_listbox.delete(0, END)
            self.tasks.clear()
            self.save_tasks()

    def load_tasks(self):
        try:
            with open("tasks.txt", "r") as file:
                for line in file:
                    task = line.strip()
                    if task:
                        self.task_listbox.insert(END, task)
                        self.tasks.append(task)
        except FileNotFoundError:
            pass

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


if __name__ == "__main__":
    root = Tk()
    app = SexyToDoList(root)
    root.mainloop()
  

This new script creates a GUI version of our To-Do List application. Now, you can add tasks using the “Add Task” button and delete tasks by selecting them and clicking the “Delete Task” button.

Source Code Of To Do List Application

OUTPUT

Ultra Sexy to-do list app

Remember that GUI programming in Python is a vast topic, with many libraries available such as PyQt, wxPython, Kivy, and others. However, for beginners, Tkinter is a great starting point as it’s simple to use and powerful enough for a wide range of applications.

Wrapping Up

We hope this beginner-friendly Python project helps you better understand the basics of Python programming. By creating a simple yet functional to-do list, you’ve taken one more step toward mastering Python!

As you continue to hone your Python skills, remember that creating and working on projects is one of the most effective ways to learn. So, keep experimenting, coding, and most importantly, having fun while doing it!

Tags : Python, Python project, Python source code, Beginner Python project, Python programming, Python to-do list, Learn Python

Post You May Also Like: