I want to update the properties of a kivy widget while running 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 is gonna show me only the final result of the loop. I'd like to keep updating the label.text while the loop goes.
I looked for something like the bind(), setter() and ask_update() functions, but if are these funcs, I didn't get how to use them.
------------------ EDIT -----------------------
Trying to adapt to inclement
answer (running the update function in other thread using Clock), I got the code below trying to follow the real idea of my problem, but still not working:
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 the func
function and make it update the label text exactly when I order the text change in update
function.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…