Python Tkinter Todo List

In this PythonTkinter tutorial, we will learn about how to create a Todo list in Python which help us to store our important ideas and daily task.

Python Tkinter todo list
Python Tkinter todo list

Python Tkinter Todo List

We create a Python Tkinter Todo List we have an interface with an entry box where we can enter the task and also have a button from which we can save our task.

Block of code:

In the following Python Tkinter Todo list block of code, we import some Tkinter modules from which we can create a Todo List.

from tkinter import *
import tkinter
import random
from tkinter import messagebox

Check this code in Repository from Github and you can also fork this code.

Github User Name: PythonT-Point

Block of code:

In the following Python Tkinter Todo List block of code, we will define an update task function in which we can update our task.

  • clearlistbox() is used to clear the list box.
  • lbltask.insert(“end”, utask) is used to insert the task inside the entry box.
  • numtask = len(tasks) is used to describe the length of the task.
def updatetask():
    clearlistbox()
    for utask in tasks:
        lbltask.insert("end", utask)
    numtask = len(tasks)
    lbldsp_count['text'] = numtask

Read: Python Tkinter temperature converter

Block of code:

In the following block of code, we define a clear list box function in which the task is deleted from the list.

def clearlistbox():
    lbltask.delete(0, "end")

Block of code:

In the following block of code, we define the add task function from which we can add our important information to the list.

def addtask():
    lbldisplay["text"] = ""
    Ntask = txtinput.get()
    if Ntask != "":
        tasks.append(Ntask)
        updatetask()
    else:
        lbldisplay["text"] = "please enter the text"
    txtinput.delete(0, 'end')

Block of code:

In the following block of code, we create a delete all function in which we can delete all the information that we can enter into the list. And also create a delete one function in which we can delete only one information that we are entered.

def deleteall():
    conf = messagebox.askquestion(
        'delet all??', 'are you sure to delete all task?')
    print(conf)
    if conf.upper() == "YES":
        global tasks
        tasks = []
        updatetask()
    else:
        pass


def deleteone():
    delt = lbltask.get("active")
    if delt in tasks:
        tasks.remove(delt)
    updatetask()

Read: Python Tkinter Simple Calculator

Block of code:

In the following block of code, we create some functions in which we can sort our task in ascending and descending order. And also generate the number of tasks.

def sortasc():
    tasks.sort()
    updatetask()


def sortdsc():
    tasks.sort(reverse=True)
    updatetask()


def randomtsk():
    randtask = random.choice(tasks)
    lbldisplay["text"] = randtask


def numbertsk():
    numtask = len(tasks)
    lbldisplay["text"] = numtask

Block of code:

In the following block of code, we create a save function from which we can save our task by simply clicking on the button and our task is saved into the Todolist.

def saveact():
    savecon = messagebox.askquestion(
        'Save confirmation', 'Save Your Progress?')
    if savecon.upper() == "YES":
        with open("SaveFile.txt", "w") as filehandle:
            for listitem in tasks:
                filehandle.write('%s\n' % listitem)
    else:
        pass

Block of code:

In the following block of code, we create a function load info and load act from which we can load our info into the list and also create a loadact function from which message box is generated if some wrong info enter.

def loadinfo():
    messagebox.showinfo(
        "info", "This is Todolist  \n created by Pythontpoint ",)


def loadact():
    loadcon = messagebox.askquestion(
        'Save Confirmation', 'save your progress?')
    if loadcon.upper() == "YES":
        tasks.clear()

        with open('SaveFile.txt', 'r') as filereader:
            for line in filereader:
                currentask = line
                tasks.append(currentask)
            updatetask()

    else:
        pass

Block of code:

In the following block of code, we create an exitapp function from which we can exit the app after completing the task.

def exitapp():
    confex = messagebox.askquestion(
        'Quit confirmation', 'Are you sue you want to quit?')
    if confex.upper() == "YES":
        wd.destroy()
    else:
        pass

Code:

In the following code, we will import the tkinter module and create a Todo list in which we can create our notes and add to the list.

from tkinter import *
import tkinter
import random
from tkinter import messagebox


def updatetask():
    clearlistbox()
    for utask in tasks:
        lbltask.insert("end", utask)
    numtask = len(tasks)
    lbldsp_count['text'] = numtask


def clearlistbox():
    lbltask.delete(0, "end")


def addtask():
    lbldisplay["text"] = ""
    Ntask = txtinput.get()
    if Ntask != "":
        tasks.append(Ntask)
        updatetask()
    else:
        lbldisplay["text"] = "please enter the text"
    txtinput.delete(0, 'end')


def deleteall():
    conf = messagebox.askquestion(
        'delet all??', 'are you sure to delete all task?')
    print(conf)
    if conf.upper() == "YES":
        global tasks
        tasks = []
        updatetask()
    else:
        pass


def deleteone():
    delt = lbltask.get("active")
    if delt in tasks:
        tasks.remove(delt)
    updatetask()


def sortasc():
    tasks.sort()
    updatetask()


def sortdsc():
    tasks.sort(reverse=True)
    updatetask()


def randomtsk():
    randtask = random.choice(tasks)
    lbldisplay["text"] = randtask


def numbertsk():
    numtask = len(tasks)
    lbldisplay["text"] = numtask


def saveact():
    savecon = messagebox.askquestion(
        'Save confirmation', 'Save Your Progress?')
    if savecon.upper() == "YES":
        with open("SaveFile.txt", "w") as filehandle:
            for listitem in tasks:
                filehandle.write('%s\n' % listitem)
    else:
        pass


def loadinfo():
    messagebox.showinfo(
        "info", "This is Todolist  \n created by Pythontpoint ",)


def loadact():
    loadcon = messagebox.askquestion(
        'Save Confirmation', 'save your progress?')
    if loadcon.upper() == "YES":
        tasks.clear()

        with open('SaveFile.txt', 'r') as filereader:
            for line in filereader:
                currentask = line
                tasks.append(currentask)
            updatetask()

    else:
        pass


def exitapp():
    confex = messagebox.askquestion(
        'Quit confirmation', 'Are you sue you want to quit?')
    if confex.upper() == "YES":
        wd.destroy()
    else:
        pass


wd = tkinter.Tk()
wd.configure(bg="white")
wd.title("Pythontpoint")
wd.geometry("260x300")
tasks = []



lbltitle = tkinter.Label(wd, text="Todo List", bg="white")
lbltitle.grid(row=0, column=0)

lbldisplay = tkinter.Label(wd, text="", bg="white")
lbldisplay.grid(row=0, column=1)

lbldsp_count = tkinter.Label(wd, text="", bg="white")
lbldsp_count.grid(row=0, column=3)

txtinput = tkinter.Entry(wd, width=15)
txtinput.grid(row=1, column=1)

txtadd_button = tkinter.Button(
    wd, text="add todo", bg="white", fg="cyan", width=15, command=addtask)
txtadd_button.grid(row=1, column=0)

delonebutton = tkinter.Button(
    wd, text="Done Task", bg="white", width=15, command=deleteone)
delonebutton.grid(row=2, column=0)

delallbutton = tkinter.Button(
    wd, text="Delete all", bg="white", width=15, command=deleteall)
delallbutton.grid(row=3, column=0)

sortasc = tkinter.Button(wd, text="sort (ASC)",
                          bg="White", width=15, command=sortasc)
sortasc.grid(row=4, column=0)

sortdsc = tkinter.Button(wd, text="sort (DSC)",
                          bg="White", width=15, command=sortdsc)
sortdsc.grid(row=5, column=0)

randombutton = tkinter.Button(
    wd, text="random task", bg="White", width=15, command=randomtsk)
randombutton.grid(row=6, column=0)

numbertsk = tkinter.Button(
    wd, text="Number of Task", bg="white", width=15, command=numbertsk)
numbertsk.grid(row=7, column=0)

exitbutton = tkinter.Button(wd, text="exit app",
                           bg="white", width=15, command=exitapp)
exitbutton.grid(row=8, column=0)

savebutton = tkinter.Button(
    wd, text="save TodoList", bg="white", width=15, command=saveact)
savebutton.grid(row=10, column=1)

loadbutton = tkinter.Button(
    wd, text="Load LastTodolist", bg="white", width=15, command=loadact)
loadbutton.grid(row=10, column=0)

infobutton = tkinter.Button(
    wd, text="info", bg="white", width=15, command=loadinfo)
infobutton.grid(row=11, column=0, columnspan=2)

lbltask = tkinter.Listbox(wd)
lbltask.grid(row=2, column=1, rowspan=7)


# main loop
wd.mainloop()

Output:

After running the above code we get the following output in which we can see that the Todo list is created on the screen.

Python Tkinter Todo list output

101 thoughts on “Python Tkinter Todo List”

  1. Вся информация, представленная на данном сайте, носит исключительно информационный характер и предназначена для ознакомления с деятельностью онлайн-казино. Сайт не являемся оператором игр и не предоставляем услуг по организации азартных игр. bnrosmuvzj … https://www.perfectpicturephotobooth.co/wp-content/otlichiya-mezhdu-onlayn-kazino-i-traditsionnymi-kazino.html

    Reply
  2. I’ve been exploring for a bit for any high-quality articles or weblog posts in this kind
    of area . Exploring in Yahoo I at last stumbled upon this website.
    Studying this info So i am happy to show that I’ve
    a very excellent uncanny feeling I found out exactly what I needed.

    I so much undoubtedly will make sure to don?t omit this web site and provides it a
    glance regularly.!

    Reply
  3. Hi! Do you know if they make any plugins to assist with Search Engine Optimization?
    I’m trying to get my site to rank for some targeted keywords but I’m not seeing very good success.
    If you know of any please share. Many thanks! I saw similar article here:
    Eco wool

    Reply
  4. sugar defender official website Uncovering Sugar
    Protector has actually been a game-changer for me, as I have actually always been vigilant about managing my blood
    glucose degrees. I currently really feel equipped and positive in my capacity to keep healthy levels,
    and my most recent health checks have actually shown this progression. Having a reliable
    supplement to match my a huge source of comfort, and I’m absolutely glad for the substantial distinction Sugar
    Protector has made in my overall wellness.

    Reply
  5. sugar defender ingredients For many years,
    I’ve fought uncertain blood sugar level swings that left me really feeling drained pipes and lethargic.
    But because incorporating Sugar Defender into my
    routine, I have actually seen a substantial improvement in my total energy and stability.

    The dreadful mid-day distant memory, and I appreciate that this
    natural treatment accomplishes these results without any undesirable
    or damaging responses. truthfully been a transformative discovery
    for me.

    Reply
  6. The next time I read a blog, Hopefully it does not disappoint me just as much as this one. After all, Yes, it was my choice to read through, nonetheless I genuinely thought you would probably have something helpful to say. All I hear is a bunch of whining about something you can fix if you were not too busy searching for attention.

    Reply
  7. When I originally commented I appear to have clicked on the -Notify me when new comments are added- checkbox and from now on every time a comment is added I receive four emails with the same comment. Perhaps there is a way you can remove me from that service? Thank you.

    Reply
  8. sugar defender Official website
    For several years, I’ve battled unforeseeable blood sugar level swings that left me really feeling drained and
    lethargic. Yet because including Sugar Defender right into my routine, I’ve discovered a considerable renovation in my total power and stability.
    The feared mid-day thing of the past, and I appreciate that this natural solution attains these outcomes without any undesirable or negative responses.
    honestly been a transformative exploration for me.

    Reply
  9. The twenty first Century Waterfront incorporated the brand new constructing with River Journey and Ross’s Landing Park, persevering with the theme of Chattanooga’s early history by locating The Passage, an interactive public artwork set up marking the positioning of the beginning of the Path of Tears in Chattanooga, alongside it.

    Reply
  10. Before you notice the sanding pad at the underside, you assume perhaps it is some kind of beefed-up trim router – not a palm sander with its bulbous prime, nor a half-sheet sander with two hand-holds and the boxy-however-streamlined look of an ’80s Okay-car transformed to a hobbyist dragster.

    Reply
  11. Your style is so unique in comparison to other folks I’ve read stuff from. I appreciate you for posting when you have the opportunity, Guess I’ll just bookmark this page.

    Reply
  12. Hi! I could have sworn I’ve been to your blog before but after looking at some of the articles I realized it’s new to me. Anyhow, I’m definitely pleased I stumbled upon it and I’ll be book-marking it and checking back regularly!

    Reply
  13. The next time I learn a weblog, I hope that it doesnt disappoint me as much as this one. I imply, I do know it was my choice to learn, however I actually thought youd have something attention-grabbing to say. All I hear is a bunch of whining about something that you could possibly fix should you werent too busy looking for attention.

    Reply
  14. hello!,I love your writing so so much! proportion we be in contact more approximately your post on AOL? I need an expert on this area to unravel my problem. Maybe that’s you! Looking forward to peer you.

    Reply
  15. I’m impressed, I must say. Truly rarely do I encounter a blog that’s both educative and entertaining, and without a doubt, you might have hit the nail within the head. Your notion is outstanding; ab muscles something that insufficient persons are speaking intelligently about. We’re very happy that I found this in my seek out something with this.

    Reply
  16. I discovered your blog web site on google and check a few of your early posts. Proceed to keep up the excellent operate. I just additional up your RSS feed to my MSN News Reader. Looking for ahead to studying extra from you later on!…

    Reply
  17. You lost me, friend. Come on, man, I imagine I buy what youre saying. I’m sure what you’re saying, but you just appear to have forgotten that might be a few other folks inside world who view this matter for it is actually and will perhaps not agree with you. You may well be turning away alot of folks that could have been lovers of your respective website.

    Reply
  18. Thanks for another great post. Where else could anybody get that kind of information in such a perfect way of writing? I have a presentation next week, and I am on the look for such information.

    Reply
  19. Nicely… to be absolutely genuine, My partner and i had not been hoping to stumble upon this kind of data accidentally, as I did, because I recently came across your blog article whilst I used to be the truth is running looking throughout AOL, looking for some thing very close up however, not a similar… On the other hand at this time I will be over happy for being here and also I want to bring that the insight is extremely intriguing even though a little bit controversial to the recognized… I’d personally say it’s as much as discussion… but I’m frightened to cause you to an opponent, ha, ha, ha… However, for those who like to dicuss at length over it, you need to response to my remark and also I will always sign up so that I’ll be informed and are available back again for much more… Your current hopeful friend

    Reply
  20. We will design you a garden pool constructing that incorporates all these makes use of, or you can opt for two separate ones and have one of our small pool sheds put in for storage and then a totally lined and insulated backyard constructing for enjoyable and entertaining.

    Reply
  21. An fascinating discussion will be worth comment. I’m sure that you should write more about this topic, it might not be described as a taboo subject but usually everyone is too little to communicate on such topics. To another location. Cheers

    Reply
  22. thank you for such a wonderful blog. Where else could anyone get that kind of info written in such a perfect way? I have a presentation that I am presently working on, and I have been on the look out for such info.

    Reply
  23. It’s been a wild week or so watching individuals who I thought hated centralized social networks because of the harm they do giddily celebrating the entry into the fediverse of a vast, surveillance-centric social media conglomerate credibly accused of enabling focused persecution and mass murder.

    Reply
  24. It’s a shame you don’t have a donate button! I’d certainly donate to this outstanding blog! I guess for now i’ll settle for book-marking and adding your RSS feed to my Google account. I look forward to fresh updates and will share this website with my Facebook group. Chat soon!

    Reply
  25. Hi there! I simply would like to give you a huge thumbs up for your excellent information you have got here on this post. I am coming back to your blog for more soon.

    Reply
  26. fitspresso reviews
    Afteг attempting numeroᥙѕ fat burning supplements with ⅼittⅼe success, I lastly found FitSpresso,
    and it has made a sіgnifіcant distinction. The mix of environment-friendly tea extract and Garcinia Cambogia has aided me lost stubborn pounds and keep a healthy weight.
    I value that it’s made from natural active ingredients,
    which straightens ԝith my commitment to a much healthier lifestyle.
    FitSpresso has not only assisted mme drop weight yet likewise improved my overall health.
    I feel more energеtic, concentгated, and prepared to
    handle the dɑy. I extremely recommend FitSpresso to anyone trying to find a
    reputable and reliable weight-loss remedy.

    Reply
  27. It’s perfect time to make some plans for the future and it is time to be happy. I have read this post and if I could I wish to suggest you few interesting things or tips. Maybe you could write next articles referring to this article. I want to read even more things about it!

    Reply

Leave a Comment