Python 3.x 调用.kv kivymd中的变量
我有一个问题,当我想调用.kv中的变量时,给了我一个错误 可以这样调用变量吗:Python 3.x 调用.kv kivymd中的变量,python-3.x,variables,kivy-language,Python 3.x,Variables,Kivy Language,我有一个问题,当我想调用.kv中的变量时,给了我一个错误 可以这样调用变量吗: FloatLayout: MDCard: orientation: "vertical" size_hint: .43, .3 height: self.minimum_height pos_hint: {"x": .05, "y": .35} MDLabel: id: card text: se
FloatLayout:
MDCard:
orientation: "vertical"
size_hint: .43, .3
height: self.minimum_height
pos_hint: {"x": .05, "y": .35}
MDLabel:
id: card
text: self.data_ebay #here is the variable i want to be the text
变量有一个文本,但当我运行它时,它给了我以下错误:
AttributeError: 'MDLabel' object has no attribute 'app'
File "E:\pythonf2\lib\site-packages\kivy\lang\builder.py", line 249, in create_handler
return eval(value, idmap), bound_list
File "<string>", line 28, in <module>
File "kivy\weakproxy.pyx", line 32, in kivy.weakproxy.WeakProxy.__getattr__
File "E:\pythonf2\lib\site-packages\kivy\lang\builder.py", line 692, in _apply_rule
rctx['ids'])
File "E:\pythonf2\lib\site-packages\kivy\lang\builder.py", line 254, in create_handler
cause=tb)
AttributeError:'MDLabel'对象没有属性'app'
文件“E:\pythonf2\lib\site packages\kivy\lang\builder.py”,第249行,在create\u处理程序中
返回eval(值,idmap),绑定列表
文件“”,第28行,在
文件“kivy\weakproxy.pyx”,第32行,在kivy.weakproxy.weakproxy.\uu getattr__
文件“E:\pythonf2\lib\site packages\kivy\lang\builder.py”,第692行,在应用规则中
rctx['id'])
文件“E:\pythonf2\lib\site packages\kivy\lang\builder.py”,第254行,在create\u处理程序中
原因(肺结核)
如果变量在app类中,则应使用“app.variable”;如果变量在包含此小部件的类中,则应使用“root.variable”。我想你的情况是:
MDLabel:
id: card
text: root.data_ebay
我试着那样做,但是没有用,还有别的办法吗?