Kivy更新标签文本

2024-09-29 02:16:29 发布

您现在位置:Python中文网/ 问答频道 /正文

我需要更新一组标签,一次一个,但是我还需要在函数完成之前查看更改的效果。期望的结果是一种加载杆。在

现在,我的代码在函数的末尾一次应用所有更改。在

(代码简化以便于阅读)

在主.py在

def TextAnimation(self):
    #self.ids.??? are labels
    self.ids.x1y1.text = "-"
    self.ids.x2y1.text = "-"
    self.ids.x3y1.text = "-"
    self.ids.x1y1.texture_update()
    self.ids.x2y1.texture_update()
    self.ids.x3y1.texture_update()
    time.sleep(0.2)
    self.ids.x4y1.text = "-"
    self.ids.x5y1.text = "-"
    self.ids.x6y1.text = "-"
    self.ids.x4y1.texture_update()
    self.ids.x5y1.texture_update()
    self.ids.x6y1.texture_update()
    time.sleep(0.2) 

我的印象是labelName.texture_update()立即调用下一帧,而不是等待函数结束,但似乎并不像文档中描述的那样工作

Warning The texture update is scheduled for the next frame. If you need the texture immediately after changing a property, you have to call the texture_update() method before accessing texture:

^{pr2}$

Tags: the函数代码textselfidstimeupdate
1条回答
网友
1楼 · 发布于 2024-09-29 02:16:29

您应该使用Clock来安排标签文本的更改。考虑以下代码:

在试验电压公司名称:

#:kivy 1.9.0
Root:
    cols: 1

    Label:
        id: my_label

    Button:
        text: 'animate text'
        on_press: root.animate_text()

在主.py公司名称:

^{pr2}$

相关问题 更多 >