如何修复AttributeError:“ NoneType”对象没有属性“ get”

时间:2020-05-09 15:20:40

标签: python tkinter

当我想从用户处获取inout并将其存储在变量中时,出现此错误 我编写的代码如下所示,请告诉我如何解决此问题

from tkinter import  *
root1 = Tk()
root1.geometry("700x330+350+300")
key = "Agcy5x7kZe"
frame = LabelFrame(root1)

def Submitcommand():
    a = entry.get()
    b = serialentry.get()
    print(a)# To check
    print(b)# To check


photo = PhotoImage(file = 'gil.png')
photo1 = Label(frame , image = photo).grid(row = 0 , column = 0 , columnspan = 2 , pady = (0 , 20))

username = Label(frame, text = "Username :" , font = "helvetica 30 bold").grid(row = 1 , column = 0)
entry = Entry(frame, bd = 5 , font = "Lucida 30 bold" , width = 25).grid(row = 1 , column = 1)


label = Label(frame, text = "Serial Key : " , font = "helvetica 30 bold").grid(row = 2 , column = 0)
serialentry = Entry(frame, bd = 5 , font = "Lucida 30 bold" , width = 25).grid(row = 2 , column = 1)

submit = Button(frame , text = "Login" , height = 2 , width = 10 , command = Submitcommand).grid(row = 3 , column = 1 , columnspan = 2 , pady = (0 , 20))
frame.place(relx = 0.5 , rely = 0.5 , anchor = CENTER)


root1.mainloop()

1 个答案:

答案 0 :(得分:0)

您必须首先创建小部件,然后再放置等。您会看到cars返回一个入口对象,因此一旦执行carsEntry()就是一个对象。该对象具有e = Entry()方法,因此一旦运行e,它便将其放置。问题是

place

e.place()

产生相同的a = Entry().place() ,但是您对此不感兴趣,您需要e = Entry() a = e.place() 。 这是您的固定代码:

a

希望有帮助!