Python 非类型对象没有要获取的属性(Tkinter)
我不知道这为什么不起作用,真的很烦人Python 非类型对象没有要获取的属性(Tkinter),python,tkinter,Python,Tkinter,我不知道这为什么不起作用,真的很烦人 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 =
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()
错误代码如下所示:
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'
回溯(最近一次呼叫最后一次):
文件“C:\Users\anglc\AppData\Local\Programs\Python\Python37-32\lib\tkinter\\uuuuuu init\uuuuuu.py”,第1705行,在调用中__
返回self.func(*args)
文件“C:/Users/anglc/Desktop/test.py”,第7行,在
按钮(root,text=“DEL3TE”,fg=“red”,command=lambda:do(r,a)).grid(行=0,列=0)
文件“C:/Users/anglc/Desktop/test.py”,第5行,在do中
s=r.get()
AttributeError:“非类型”对象没有属性“get”
我不知道怎么修,请帮忙,谢谢 在这一行中:
按钮(root,text=“DEL3TE”,fg=“red”,command=lambda:do(r,a)).grid(行=0,列=0)
在lambda之后,您需要给出:
按钮(root,text=“DEL3TE”,fg=“red”,command=lambda r,a:do(r,a)).grid(行=0,列=0)
由于do函数只获得传递给do函数的实际值所需的None值。如果要创建条目,请确保其格式不是这样的:
r = Entry(root, width=15, bg="white").grid(row=0, column=1)
删除AttributeError应该是这样的:
r = Entry(root, width=15, bg="white")
r.grid(row=0, column=1)
这给了我一个新的错误,()缺少2个必需的位置参数:'r'和'a'是一个类型错误Btwy您必须首先为r和a赋值,然后调用函数do。仍然无法从tkinter导入*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)按钮(root,text=“DEL3TE”,fg=“red”,command=lambda r,a:do(r,a)).grid(row=0,column=0)标签(text=“text1”).grid(row=1,column=2)标签(text=“text2”).grid(row=0,column=2)标签(text=“您已获得死亡笔记”,fg=“red”).grid(row=2,column=0)mainloop()错误是什么