';非类型';对象没有属性';获取';在python小程序中

';非类型';对象没有属性';获取';在python小程序中,python,tkinter,compiler-errors,Python,Tkinter,Compiler Errors,这段代码运行,但当我按下它创建的按钮时崩溃。这是我的第一篇帖子,所以如果你有提示或者需要更多信息,请发表评论。 程序应将框中的变量保存在全局变量中。但当我试图按下按钮时,出现了错误 from tkinter import * finestra1 = Tk() finestra1.title("Prima Finestra") testo1 = Label(finestra1, text ="Inserire modello infissi").grid(row=0, column=0) sp

这段代码运行,但当我按下它创建的按钮时崩溃。这是我的第一篇帖子,所以如果你有提示或者需要更多信息,请发表评论。 程序应将框中的变量保存在全局变量中。但当我试图按下按钮时,出现了错误

from tkinter import *

finestra1 = Tk()
finestra1.title("Prima Finestra")

testo1 = Label(finestra1, text ="Inserire modello infissi").grid(row=0, column=0)
spazioinput1 = Entry(finestra1, width=10, borderwidth=5).grid(row=0, column=1)
testo2= Label(finestra1, text ="Inserire numero finestre").grid(row=1, column=0)
spazioinput2 = Entry(finestra1, width=10, borderwidth=5).grid(row=1, column=1)
testo3= Label(finestra1, text ="Inserire numero balconi").grid(row=2, column=0)
spazioinput3 = Entry(finestra1, width=10, borderwidth=5).grid(row=2, column=1)


def primobottone():
    # global modelloinfissi
    global numerofinestre
    global numerobalconi
    modelloinfissi = spazioinput1.get()
    numerofinestre = int(spazioinput3.get())
    numerobalconi = int(spazioinput2.get())
    Label(finestra1, text="Modello: " +modelloinfissi +" \nnumero: "+ numerobalconi+numerofinestre)



bottone1 = Button(finestra1, text= "Avanti", command = primobottone).grid(row=3)
finestra1.mainloop()
我遇到的错误是:

Error:

Exception in Tkinter callback
Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/tkinter/__init__.py", line 1883, in __call__
    return self.func(*args)
  File "/Users/salvatorefroncillo/Desktop/progetto/progetto.py", line 18, in primobottone
    modelloinfissi = spazioinput1.get()
AttributeError: 'NoneType' object has no attribute 'get'
Entry.grid()
返回
None
,因此在此行之后:

spazioinput1 = Entry(finestra1, width=10, borderwidth=5).grid(row=0, column=1)
您的
spazioinput1
确实是
None
。您需要将其拆分为两条语句:

spazioinput1 = Entry(finestra1, width=10, borderwidth=5)
spazioinput1.grid(row=0, column=1)

当然,对所有小部件也要这样做…

谢谢,我解决了这个问题,没有问题。再次非常感谢