Kivy标签文字开始更新为时已晚

时间:2019-12-17 15:58:02

标签: python kivy

我想要的是标签文本,该文本显示了按下按钮的次数,但是由于某种原因,它仅在我按下2后才开始起作用,我似乎无法弄清楚为什么第一次不更新按下按钮。

这是我的python文件:

import kivy
from kivy.app import App
from kivy.lang import Builder
from kivy.uix.gridlayout import GridLayout
from kivy.uix.button import Button
from kivy.uix.widget import Widget
from kivy.properties import NumericProperty
from kivy.clock import Clock

class Testime(Widget):
    pass

class loendtest(App):
    tulemus = NumericProperty()
    loend = [0]
    def update(self, *args):
        self.loend = self.loend

    def build(self):
        Clock.schedule_interval(self.update, 0.2)
        return Testime()

if __name__ == "__main__":
    loendtest().run()

这是kv:

<Testime>:
    GridLayout:
        cols:2
        size: root.size
        Button:
            text: "lisa tulemus"
            on_press:
                app.tulemus += 1
                app.loend.append(app.tulemus)
                print(app.tulemus)
                print(app.loend)


        Label:
            text: str(app.loend[app.tulemus-1]+1) if len(app.loend) > 1 else "0"

1 个答案:

答案 0 :(得分:0)

这是您所需要的代码的简化版本。为方便起见,我将FROM python:3.7 WORKDIR /var/blah COPY assertions/ ./assertions/ ... COPY requirements.txt ./ COPY datastore/ ./datastore/ COPY *.py ./ RUN pip3 install -r requirements.txt ENTRYPOINT ["python", "dataloader.py"] 添加为kv。可以将其他内容添加到代码中,但以下是满足您的要求所需的全部内容:

Builder.load_string()