问题
I have a problem, that when i want to call a variable in the .kv gave me an error
is it posible to call a variable like this:
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
The variable has a text but when i run it, it gave me this error:
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)
回答1:
You should use 'app.variable' if the variable in the App class or 'root.variable' if it's in the class that contains this widget. I suppose in your case it would be:
MDLabel:
id: card
text: root.data_ebay
来源:https://stackoverflow.com/questions/60160749/how-to-call-a-variable-in-kv-kivymd