Build a To-Do Application Using Python

9 Min Read

A To-Do application, sometimes referred to as a task manager, lets users organize and manage their tasks more effectively. You can create a list of daily or weekly tasks, set deadlines and reminders, prioritize them, track their progress, and share them with others.

A To-Do app lets you manage time, boost productivity, and reduce stress. So, how can you build one in Python?


The Tkinter Module

You can use Tkinter to build the To-Do application. Tkinter allows you to create desktop applications. It offers a variety of widgets like buttons, labels, and text boxes that make it easy to develop apps. Some of the applications you can develop using Tkinter include a Dictionary app, Music Player, a Weight Conversion tool, and a Word Jumble game.

To install Tkinter, open a terminal and run:

 pip install tkinter 

How to Build a To-Do Application Using Python

Import the Tkinter module and initialize the root window. Using the configure() function, set the background color. Also set the title and the size of the window.

 from tkinter import *
from tkinter.font import Font

root = Tk()
root.title('To-Do List Application')

Define a font style and a frame widget. A frame acts as a container and is responsible for arranging the position of other widgets. Set the parent window you want to place it in and give it a vertical padding of 10.

Define a listbox widget. This component displays a list of items for the user to select. Set the parent window you want to place it in, the font style, the width, the height, the background color, the border width, and the font color. Also, set the focus highlight’s thickness, the background color it should have when selected, and the appearance of the active line as None.

Organize the list by placing it on the left side and telling it to fill in any extra space in both directions.

 my_font = Font(family="Arial", size=22, weight="bold")
my_frame = Frame(root)

my_list = Listbox(my_frame, font=my_font, width=40, height=7, bg="#cf9fff", bd=0, fg="#5c4033", highlightthickness=0, selectbackground="#ff0000", activestyle="none")
my_list.pack(side=LEFT, fill=BOTH)

Define a scrollbar that the program will display on the right side of the frame, filling any extra space in both directions. use the config() method to bind the scrollbar to the listbox widget you defined earlier. On setting the value of the yscrollcommand US my_scrollbar. set it gets the current position of the scrollbar on user interaction.

On setting the command parameter as my_list. yview, the scrollbar’s movement gets linked to the up and down functions. So, when the user interacts with the scrollbar, the listbox views change accordingly.

 my_scrollbar = Scrollbar(my_frame)
my_scrollbar.pack(side=RIGHT, fill=BOTH)

Define an entry widget to accept tasks as input from the user. Set the parent window you want to place it in, the font style, the width, and the background color. Organize it by adding a padding of 20 in the vertical direction.

Define a frame to organize your buttons. Place them in the root window and give it a background color. Organize the frame with a padding of 20 in the vertical direction as well.

 my_entry = Entry(root, font=("Arial", 22), width=26, bg='#cf9fff')

button_frame = Frame(root, bg='#a020f0')

define a function, delete_item(). Pass the ANCHOR parameter to the delete function to remove the selected item from the list.

 def delete_item():

define a function, add_item(). use the get() function to retrieve the input value by the user to the end of the list. If the list is empty, the element added will be the first entry in the list. After adding the element to the list you need to remove it from the entry widget. Use the delete function to remove the text inserted from the beginning to the end of its length.

 def add_item():
    my_list.insert(END, my_entry.get())
    my_entry.delete(0, END)

define a function, cross_off_item(). use the item_config() method to change the font color of the selected item task in the list to a faint color, you have crossed off the item. Clear the selection you made now from the beginning to the end of its length.

 def cross_off_item():
    my_list.itemconfig(my_list.curselection(), fg="#dedede")
    my_list.selection_clear(0, END)

define a function, uncross_item(). Similar to the above function, change the color of the selected task back to the original and clear the selection completely.

 def uncross_item():
    my_list.itemconfig(my_list.curselection(), fg="#5c4033")
    my_list.selection_clear(0, END)

define a function, delete_crossed(). Define a counter variable and iterate until it is less than the size of the list. If the item’s font color is faint, delete that item from the list. Otherwise, continue the iteration by incrementing the counter variable.

 def delete_crossed():
    count = 0

    while count < my_list.size():
        if my_list.itemcget(count, "fg") == "#dedede":
            count += 1

Define five buttons: delete, add, cross off, uncross off, and delete crossed off. Place the buttons in the button frame you created earlier. Set the text each button should display, the function it should run when you click it, its background color, and font style.

 delete_button = Button(button_frame, text="Delete Item", command=delete_item, bg="#e7305b", font=("arial", 12, "bold"))
add_button = Button(button_frame, text="Add Item", command=add_item, bg="#e7305b", font=("arial", 12, "bold"))
cross_off_button = Button(button_frame, text="Cross Off Item", command=cross_off_item, bg="#e7305b", font=("arial", 12, "bold"))
uncross_button = Button(button_frame, text="Uncross Item", command=uncross_item, bg="#e7305b", font=("arial", 12, "bold"))
delete_crossed_button = Button(button_frame, text="Delete Crossed", command=delete_crossed, bg="#e7305b", font=("arial",12, "bold"))

Organize the buttons using the grid manager in a single row and five columns. Set a padding of 0 in the horizontal direction to allot some spacing between the buttons,

 delete_button.grid(row=0, column=0)
add_button.grid(row=0, column=1, padx=20)
cross_off_button.grid(row=0, column=2)
uncross_button.grid(row=0, column=3, padx=20)
delete_crossed_button.grid(row=0, column=4)

the mainloop() function tells Python to run the Tkinter event loop and listen for events until you close the window.


Put all the code together and never miss out on any task using this efficient To-Do List application.

Output of To-Do Application Using Python

On running the program above, a window appears in which you can enter the tasks you want to complete. On adding the task and pressing the Add Items button, the task gets added to the screen.

To Do Application Add item demo

On selecting any of the tasks with the mouse/keyboard and clicking the Cross Off Items button, the selected task changes its color and turns faint.

To Do Application cross off demo items

On selecting the crossed item and clicking the Uncross Items button, the program highlights the task back to its original color.

To Do Application uncross demo items

On clicking the Delete Crossed button, the program deletes the crossed-off task. On selecting any item and clicking the Delete Items button, the selected item gets removed.

To Do Application delete cross item demo

Applications You Can Build Using Python to Boost Your Productivity

You can build applications such as RescueTime which tracks how much time a user spends on which app. Such apps can help you discover which websites cause you the most distraction. Apart from this, you can take inspiration from Trello to create boards with to-do lists, deadlines, and reminders.

A music application that plays a specially designed playlist to help users concentrate and focus on work. You can even automate GUI programs to perform repetitive tasks like login processes and scripts to interact with the desktop.

Share this Article