在.kv kivymd中调用变量 [英] calling a variable in .kv kivymd
本文介绍了在.kv kivymd中调用变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个问题,当我想在.kv中调用一个变量时,我遇到了一个错误
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)
推荐答案
如果App类中的变量,则应使用"app.variable";如果包含此小部件的类中的变量,则应使用"root.variable".我想在您的情况下应该是:
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
这篇关于在.kv kivymd中调用变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文