您好我试图使用self.ids从不同的类访问对象的属性..但是我得到了这个恼人的错误 AttributeError:'super'对象没有属性'__getattr __' 这是我的代码,当我点击“按钮为男孩”我得到错误
.py文件
from kivy.app import App
from kivy.uix.boxlayout import BoxLayout
from kivy.properties import ObjectProperty
class Get_People(BoxLayout):
root_lbl=ObjectProperty()
class Get_Boys(BoxLayout):
label_b=ObjectProperty()
def show(self):
self.ids. root_lbl.text='i am called'
class lstApp(App):
def build(self):
self.load_kv('dates_test.kv')
return Get_People()
if __name__=='__main__':
lstApp().run()
这是.Kv文件
<Get_People>:
root_lbl: root_lbl
orientation: 'vertical'
Button:
name: root_btn
id: root_btn
text: "I am Root Button"
Label:
id: root_lbl
text: "I am Root Label"
Get_Boys:
<Get_Boys>:
label_b: label_b
Button:
id: button_b
text: "Button for boys"
on_press: root.show()
Label:
id: label_b
text: "Label for boys"
答案 0 :(得分:0)
如果我们发现我们发现Get_Boys
的孩子是button_b
和label_b
,那么这些是可以通过ids
访问的元素。但是,如果我们查看Get_People
,Get_Boys
是一个孩子,那么您可以通过Get_People
方法访问parent
,然后通过root_lbl
访问:
class Get_Boys(BoxLayout):
label_b=ObjectProperty()
def show(self):
self.parent.root_lbl.text='i am called'