【发布时间】:2020-07-11 17:56:46
【问题描述】:
我想用简单的话将 .kv 文件中的一个函数绑定到 .py 文件中的一个方法 我想每天在我的应用程序的主屏幕上更新引号,所以我使用屏幕小部件来显示引号所以我该怎么做将 label.text 绑定到 .py 文件中的方法 这是我要绑定的 .py 文件的类
class MainScreen(FloatLayout):
def quote(self):
self.quote.text = 'I often think that the night is more alive and more richly colored than
the day. - Vincent van Gogh'
这是 .kv 文件的根部件
<MainScreen>:
story: story
canvas:
Color:
rgba: 0, 0, 0, 1
Rectangle:
pos: self.pos
size: self.size
Label:
id: story
text: root.quote
font_size: '20sp'
size: self.texture_size
pos_hint: {'x': -0.2, 'y': 0.27}
但它显示错误说 label.text 必须是字符串
【问题讨论】:
-
这能回答你的问题吗? Python Kivy: Update Label
标签: python-3.x text label kivy kivy-language