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

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

AttributeError: 'BoxLayout' 對象沒有屬性,textinput

AttributeError: 'BoxLayout' 對象沒有屬性,textinput

慕俠2389804 2023-06-20 17:11:07
按下按鈕時出現問題:我總是得到下面的錯誤。誰能建議我如何解決這個問題?主.py文件:class MainApp(MDApp):    def build(self):        self.dati = Builder.load_file("conf.kv")        return Builder.load_file("conf.kv")    def show_data(self):        print(self.boxlay.btn_nav.scr1.classe.text)MainApp().run()conf.kv 文件:BoxLayout:    orientation:'vertical'    id: boxlay    btn_nav:btn_nav    MDToolbar:        title: 'Bottom navigation'    MDBottomNavigation:        id: btn_nav        scr1:scr1        MDBottomNavigationItem:            id: scr1            classe:classe            name: 'screen 1'            text: 'Python'            icon: 'language-python'            MDTextField:                id: classe                hint_text: "Enter Class"                pos_hint:{'center_x': 0.5, 'center_y': 0.5}                size_hint_x:None                width:300            MDRectangleFlatButton:                text: 'Python'                pos_hint: {'center_x': 0.5, 'center_y': 0.4}                on_release: app.show_data()運行此代碼我收到的錯誤是:  on_release: app.show_data()   File "main.py", line 27, in show_data     print( AttributeError: 'NoneType' object has no attribute 'btn_nav') AttributeError: 'BoxLayout' object has no attribute 'classe'感謝您的幫助
查看完整描述

1 回答

?
慕少森

TA貢獻2019條經驗 獲得超9個贊

由于您已經ids定義,您可以在 python 代碼中使用它們來訪問從您的kv. 所以show_data()方法可以是:


def show_data(self):

    print(self.root.ids.classe.text)

另外,我注意到你在打電話:


Builder.load_file("conf.kv")

在你的方法中兩次build()。雖然這不是錯誤,但它可能不是您想要的。該行:


self.dati = Builder.load_file("conf.kv")

創建由以下行創建的 GUI 的完整副本:


return Builder.load_file("conf.kv")

但是, 所引用的小部件樹self.dati不是您的 GUI 中的小部件樹,因此self.dati可能沒有價值。我懷疑你的build()方法應該是:


def build(self):

    self.dati = Builder.load_file("conf.kv")

    return self.dati


查看完整回答
反對 回復 2023-06-20
  • 1 回答
  • 0 關注
  • 161 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

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

幫助反饋 APP下載

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

公眾號

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