2

I don't know why this is not working and it is really annoying,

from tkinter import *

root = Tk()
def do(r, a):
    s = r.get()
    p = a.get()
Button(root, text="DEL3TE", fg="red", command=lambda: do(r, a)).grid(row=0, column=0)
r = Entry(root, width=15, bg="white").grid(row=0, column=1)
a = Entry(root, width=15, bg="white").grid(row=1, column=1)
Label(text="text1").grid(row=1, column=2)
Label(text="text2").grid(row=0, column=2)
Label(text="You have obtained the death note", fg="red").grid(row=2, column=0)
mainloop()

The error code is as follows:

Traceback (most recent call last):
  File "C:\Users\anglc\AppData\Local\Programs\Python\Python37-32\lib\tkinter\__init__.py", line 1705, in __call__
    return self.func(*args)
  File "C:/Users/anglc/Desktop/test.py", line 7, in <lambda>
    Button(root, text="DEL3TE", fg="red", command=lambda: do(r, a)).grid(row=0, column=0)
  File "C:/Users/anglc/Desktop/test.py", line 5, in do
    s = r.get()
AttributeError: 'NoneType' object has no attribute 'get'

I can't figure out how to fix it, please help, thank you!

Siong Thye Goh
  • 3,518
  • 10
  • 23
  • 31
Cryptic Arrow
  • 198
  • 1
  • 8

2 Answers2

12

If you are making an entry, be sure that it is not formatted like this:

r = Entry(root, width=15, bg="white").grid(row=0, column=1)

It should be like this to remove an AttributeError:

r = Entry(root, width=15, bg="white")
r.grid(row=0, column=1)
Cryptic Arrow
  • 198
  • 1
  • 8
0

In this line : Button(root, text="DEL3TE", fg="red", command=lambda: do(r, a)).grid(row=0, column=0)

After lambda you need to give :

Button(root, text="DEL3TE", fg="red", command=lambda r,a: do(r, a)).grid(row=0, column=0)

As you the do function only get the None value that you have need to pass real value you the do function.

Prashant Suthar
  • 292
  • 3
  • 11
  • This gives me a new error, () missing 2 required positional arguments: 'r' and 'a' its a TypeError btw – Cryptic Arrow Feb 22 '19 at 04:11
  • you have to first assign values to r and a and then call the function do. – Prashant Suthar Feb 22 '19 at 04:13
  • still doesn't work – Cryptic Arrow Feb 22 '19 at 04:13
  • from tkinter import * root = Tk() def do(r, a): s = r.get() p = a.get() r = Entry(root, width=15, bg="white").grid(row=0, column=1) a = Entry(root, width=15, bg="white").grid(row=1, column=1) Button(root, text="DEL3TE", fg="red", command=lambda r,a: do(r, a)).grid(row=0, column=0) Label(text="text1").grid(row=1, column=2) Label(text="text2").grid(row=0, column=2) Label(text="You have obtained the death note", fg="red").grid(row=2, column=0) mainloop() – Cryptic Arrow Feb 22 '19 at 04:13
  • whats the error – Prashant Suthar Feb 22 '19 at 04:14
  • That doesnt work for me and it defines r and a before – Cryptic Arrow Feb 22 '19 at 04:14
  • Exception in Tkinter callback Traceback (most recent call last): File "C:\Users\anglc\AppData\Local\Programs\Python\Python37-32\lib\tkinter\__init__.py", line 1705, in __call__ return self.func(*args) TypeError: () missing 2 required positional arguments: 'r' and 'a' – Cryptic Arrow Feb 22 '19 at 04:14
  • I was able to fix it on my own, thanks though! – Cryptic Arrow Feb 22 '19 at 04:20