亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

'NoneType' 對象在 python 小程序中沒有屬性 'get'

'NoneType' 對象在 python 小程序中沒有屬性 'get'

慕標5832272 2022-08-25 16:24:23
此代碼運行,但當我按下它創建的按鈕時崩潰。這是我的第一篇文章,所以如果你有提示或如果你需要更多信息,請發表評論。程序應將框的變量保存在全局變量中。但是當我嘗試按下按鈕發生錯誤時。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 callbackTraceback (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'
查看完整描述

1 回答

?
HUX布斯

TA貢獻1876條經驗 獲得超6個贊

Entry.grid()返回 ,因此在此行之后:None

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

你的確實是.您需要將其拆分為兩個語句:spazioinput1None

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

當然,對于您的所有小部件,請執行相同的操作...


查看完整回答
反對 回復 2022-08-25
  • 1 回答
  • 0 關注
  • 94 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號