为什么Kivy在我需要的时候不刷新updating我的屏幕?

问题描述 投票:0回答:1

我遇到了这个问题。

我们创建了一个屏幕来显示同步事件中出现的消息,比如说,可能持续一分钟。或多或少每两秒钟就会有一条消息。

我想当收到一条消息时,该消息会被立即打印出来。

但是这段代码发生的情况是,当整个同步结束时,所有的消息都会被一次打印出来,而不是像预期的那样,当每条消息到来时才打印出来。

.py:

class SyncScreen(Screen):
    content = StringProperty()

    def on_enter(self):
        self.content = "Synchronization messages"
        controller.synchronize(self.update_text)

    def update_text(self, msg):    # Callback
        self.content = self.content + msg

kv:

<SyncScreen>:
    MDBoxLayout:
        orientation: "vertical"
        MDToolbar:
            title: "Synchronization"
        MDBoxLayout:
            orientation: "vertical"
            padding: 10
            TextInput:
                text: root.content
                size_hint: 1.0, 1.0
                multiline: True
python kivy kivy-language
1个回答
1
投票

你的 synchronize 函数被阻塞,Kivy在它返回之前不能画任何东西。在一个线程中运行它,或者做一些事情,比如让它每一帧返回(并被重新安排)。

© www.soinside.com 2019 - 2024. All rights reserved.