python kivy kv模板调用_Kivy:如何在Python中引用kv ID?

我是Kivy新手,我认为这是可能的,但是我搞不懂-当按下一个按钮时,我如何更新Kivy标签,但只能通过在Python中引用Kivy id?(我尝试这样做的原因是,在我的实际应用程序中,我希望一次更新几个标签,我希望我可以在我的应用程序中的button_pressed等效按钮中完成所有操作)。在

在下面这个简单的例子中,我只是尝试按下按钮,然后将标签更新为“Updated!”在

非常感谢!在

我的Python代码:from kivy.app import App

from kivy.uix.boxlayout import BoxLayout

from kivy.uix.widget import Widget

from kivy.properties import StringProperty

import random

class TestingWidget(BoxLayout):

# This is the kv id of the Label I would like to update

label_to_update = StringProperty('')

# This is the action I would like to happen when the button is pressed

def button_pressed(self):

label_to_update.text = 'Updated!'

class TestButtonApp(App):

def build(self):

return TestingWidget()

if __name__ == '__main__':

TestButtonApp().run()

我的kv文件:

^{pr2}$

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值