简体   繁体   中英

Why Kivy is not refreshing/updating my screen when I need it?

I am having this problem:

A screen was created to show the messages that comes during an synchronization event that may last one minute, for example. More or less every two seconds one message will come.

I was expexting that when a message was received that message would be immediately printed.

But what happens with this code is that all the messages are printed at once when the whole syncronizarion ends, and not when each message comes, as expected.

.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

Your synchronize function is blocking, Kivy can't draw anything until it returns. Run it in a thread, or do something like have it return (and get re-scheduled) every frame.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM