-2

I recently started coding in python 3.6 with tkinter and tried creating my own project on repl.it. The project is a simple interactive to-do list, however I am stuck and cant get the function to work. The function is just simply getting the entry and adding it to a list box, but when I try adding the function it returns

'NoneType' object has no attribute 'get'

Here is the code:

from tkinter import *

root = Tk()

#giving the window its colour 
root.configure(bg = '#40e0d0')

#changing the size of the window
root.geometry('200x500')

#creating an empty List
tasks = []

#creating the functions

def uplistbox():
    # clearing the current list
    clear_listbox()
    # populating the Listbox
    for task in tasks:
        lb.insert('end', task)

def addingtask():
  #getting the task
  tasks = ti.get()
  #adding the task to the Listbox
  tasks.append(task)
  #updating the listbox
  uplistbox()




#creating the title and adding the display below it
lbl1 = Label(root, text='To-Do-List', bg = 'red').pack()
display = Label(root, text='', bg = 'yellow').pack()

ti = Entry(root, width = 15).pack()

# adding buttons 

btn1 = Button(root, text = 'Add task', bg = 'yellow', command = addingtask).pack()
btn2 = Button(root, text = 'Delete All', bg = 'yellow').pack()
btn3 = Button(root, text = 'Delete', bg = 'yellow').pack()
btn4 = Button(root, text = 'Sort(asc)', bg = 'yellow').pack()
btn5 = Button(root, text = 'Sort(desc)', bg = 'yellow').pack()
btn6 = Button(root, text = 'Choose random', bg = 'yellow').pack()
btn7 = Button(root, text = 'Number of tasks', bg = 'yellow').pack()
btn8 = Button(root, text = 'exit', bg = 'yellow').pack()

lb = Listbox(root, bg = 'white').pack()

root.mainloop()

Can anyone tell me what I'm doing wrong?

Giorgos Myrianthous
  • 36,235
  • 20
  • 134
  • 156
  • FWIW, the reason I downvoted is that a simple search on this site for the error message yields many relevant answers. Even just typing in the exact title of this question gives me a possible duplicate right in the form for the question. – Bryan Oakley Jan 24 '20 at 15:13

2 Answers2

1

The error indicates that the object instantiation on the following line has returned None instead of an instance of Entry:

ti = Entry(root, width = 15).pack()

Therefore

tasks = ti.get()

fails because ti is of type None instead of type Entry.

The following should do the trick:

def addingtask():
  # getting the task
  ti = Entry(root, width = 15)
  ti.pack()
  tasks = ti.get()

  # adding the task to the Listbox
  tasks.append(task)

  # updating the listbox
  uplistbox()
Giorgos Myrianthous
  • 36,235
  • 20
  • 134
  • 156
0

You should replace the following:

ti = Entry(root, width = 15).pack()

To:

ti = Entry(root, width = 15)
ti.pack()

Because Entry.pack returns nothing, which assigns your ti to None.

Jordan Brière
  • 1,045
  • 6
  • 8