To Do List Using Python

Introduction:

In this project, we will demonstrate how to use Python to create a To Do List. To add and remove tasks from this To Do List, a graphical user interface (GUI) is used. This To Do list was created with the Tkinter package, which allows for the quick and easy creation of GUI applications. This program has a straightforward design with an entry, a button, and a menu. Grab a cup of coffee, take a seat, and begin using the To Do List Application.

Explanation:

This To Do List application is a graphical user interface (GUI) program that adds and removes tasks using a button and displays all tasks added using the Tkinter library’s list component. The task may be added by typing the task name in the entry and hitting the add task button. A job may also be removed by choosing it from the list and then clicking the delete task button.

Tkinter is a Python package that makes it simple to construct graphical user interfaces. Tkinter is a graphical user interface for the Tk GUI toolkit. The program makes use of Tkinter library components such as Entry, Button, and List, among many others.


The following methods were utilized in the project:


def add_task(self):


The task is added to the list using this method.


def remove_task(self):


The task is removed from the list using this method.


def update_listbox(self):


This technique is used to refresh the task list after removing or adding a new task.

source code :

import tkinter as tk
from tkinter import messagebox

class TodoApp:
    def __init__(self, root):
        self.root = root
        self.root.title("To-Do List App")

        self.tasks = []

        self.task_entry = tk.Entry(root, width=40)
        self.task_entry.pack(pady=10)

        self.add_button = tk.Button(root, text="Add Task", command=self.add_task)
        self.add_button.pack()

        self.task_listbox = tk.Listbox(root, width=40)
        self.task_listbox.pack(pady=10)

        self.remove_button = tk.Button(root, text="Remove Task", command=self.remove_task)
        self.remove_button.pack()

    def add_task(self):
        task = self.task_entry.get()
        if task:
            self.tasks.append(task)
            self.update_listbox()
            self.task_entry.delete(0, tk.END)
        else:
            messagebox.showwarning("Warning", "Please enter a task.")

    def remove_task(self):
        selected_index = self.task_listbox.curselection()
        if selected_index:
            index = selected_index[0]
            del self.tasks[index]
            self.update_listbox()
        else:
            messagebox.showwarning("Warning", "Please select a task to remove.")

    def update_listbox(self):
        self.task_listbox.delete(0, tk.END)
        for task in self.tasks:
            self.task_listbox.insert(tk.END, task)

def main():
    root = tk.Tk()
    app = TodoApp(root)
    root.mainloop()

if __name__ == "__main__":
    main()

Leave a Comment