Updating kivy widget properties while running code

I want to update the properties of a kivy widget at runtime of something ...

Example:

class app(App):
    def build(self):
        self.layout = Layout()
        self.name = Label(text = "john")
        self.layout.add_widget(self.name)
        return self.layout

    def update(self):
        for i in range(50): #keep showing the update
            self.name.text = str(i)
            #maybe some sleep here

obj = app()
obj.run()
obj.update()

This will show me only the end result of the loop. I would like to keep updating label.text while the loop continues.

I was looking for something like the bind (), setter () and ask_update () functions, but if these functions, I did not get how to use them.

------------------ EDIT -----------------------

Trying to adapt to inclementanswer (starting the update function in another thread using Clock), I got the code below, trying to understand the real idea of ​​my problem, but still does not work:

class main():
    def __init__(self, app):
        self.app = app

    ... some code goes here ...

    def func(self):
        Clock.schedule_once(partial(self.app.update, self.arg_1, self.arg_2), 0)

class app(App):
    def build(self):
            self.main = main(self)
            self.layout = Layout()
            self.name = Label(text = "john")
            self.layout.add_widget(self.name)
            return self.layout

    ... some code goes here ...

    def update(self, dt, arg_1, arg_2):
        self.name = arg_1
        sleep(5)
        self.name = arg_2

obj = app()
obj.run()

I need to call a function funcand update the label text when I order the text change in update.

+3
2

. kivy. - .

from kivy.clock import Clock

class app(App):
    def build(self):
        self.layout = Layout()
        self.name = Label(text = "john")
        self.layout.add_widget(self.name)
        self.current_i = 0
        Clock.schedule_interval(self.update, 1)
        return self.layout

    def update(self, *args):
        self.name.text = str(self.current_i)
        self.current_i += 1
        if self.current_i >= 50:
            Clock.unschedule(self.update)
+2

, - , , :

def update(self, dt, arg_1, arg_2):
    self.name = arg_1
    sleep(5)
    self.name = arg_2

arg1, arg2, , , , , . , . :

def update(self, dt, arg_1, arg_2):
    self.name.text = arg_1
    sleep(5)
    self.name.text = arg_2

StringProperty self.name.text, . , .

0

Source: https://habr.com/ru/post/1671125/


All Articles