Python 属性错误:';非类型';对象没有属性';ids';(self.root返回';无';)
我正试图从.py文件访问.kv文件中由其ID定义的按钮/标签,并更改其“文本”值。 所以我在构建函数中写道:Python 属性错误:';非类型';对象没有属性';ids';(self.root返回';无';),python,kivy,Python,Kivy,我正试图从.py文件访问.kv文件中由其ID定义的按钮/标签,并更改其“文本”值。 所以我在构建函数中写道: #self.root.ids.button.text='newValue' 它说AttributeError:'NoneType'对象没有属性“id” 我尝试了很多方法从班上其他地方访问“self.root”,但没有一种有效 我想知道为什么我在班上没有自己的根 这是我的kv文件: <MyRun>: BoxLayout: id:bx1
#self.root.ids.button.text='newValue'
它说AttributeError:'NoneType'对象没有属性“id”
我尝试了很多方法从班上其他地方访问“self.root”,但没有一种有效
我想知道为什么我在班上没有自己的根
这是我的kv文件:
<MyRun>:
BoxLayout:
id:bx1
orientation: 'vertical'
spacing: 10
padding: [20]
canvas:
Color:
rgba: .6, .6, .6, .3
Rectangle:
size: root.size
source: 'pic\germanFlag.png'
ActionBar:
ActionView:
id: av
ActionPrevious:
with_previous: False
title: 'DeutschLerne'
Label:
id:qtitle
text: 'Percentage of Question Answered:{}%'.format(int(7))
font_size: '30sp'
size_hint_y: None
height: '48dp'
Label:
id:qbody
text: 'The answer is '+('{}'.format(str("Richtig!")) if 1>0 else '{}'.format(str("Falsch!")))
color: [.3, 1, .5, 1] if 1>0 else [1, .2, .3, 1]
font_size: '30sp'
size_hint_y: None
height: '48dp'
Widget:
canvas:
Color:
rgba: .6 , .6 , .6 , .3
Rectangle:
source: "pic\questionCanvas.png"
size: [self.width,self.height*3]
pos: [self.x,self.y-300]
BoxLayout:
id:bx2
spacing: 10
padding: [10, 200 , 10 , 0]
Button:
id:selA
text: 'A'
size_hint_y: None
size_hint_x: .5
on_release: app.answer(self.text)
on_release: app.disableButton(self)
Button:
id:selB
text: 'B'
size_hint_y: None
size_hint_x: .5
on_release: app.answer(self.text)
on_release: app.disableButton(self)
Button:
id:selC
text: 'C'
size_hint_y: None
size_hint_x: .5
on_release: app.answer(self.text)
on_release: app.disableButton(self)
Button:
id:selD
text: 'D'
size_hint_y: None
size_hint_x: .5
on_release: app.answer(self.text)
on_release: app.disableButton(self)
#on_release: app.go_screen(0)
ProgressBar:
id: pb
size_hint_x: 1
size_hint_y: None
height: '48dp'
value: (app.time * 20) % 100.
我是新来的。对不起,那些难看的密码。我仍在学习如何提出一个好问题。根属性设置为您从构建方法返回的任何内容,因此当您尝试访问它时它不存在(或者更确切地说,它的默认值为“无”) 不过,您不需要它,因为您无论如何都有对小部件的引用。您可以将生成方法的结尾更改为
root = MyRun()
root.ids.selA.text='newValue'
return root
root = MyRun()
root.ids.selA.text='newValue'
return root