I have a problem when I try to update label text during a for loop. There are similar entries (for example: Updating the properties of the kivy widget when the code runs ), but they do not seem to correspond to my problem exactly (or I missed the point ...). I run the following code:
.* R:
from kivy.app import App
from kivy.uix.boxlayout import BoxLayout
from kivy.properties import StringProperty
class MyBox(BoxLayout):
tobeupd = StringProperty()
def __init__(self,*args,**kwargs):
super(MyBox,self).__init__(*args,**kwargs)
self.tobeupd = '#'
def upd_ltxt(self):
for i in range(1,10):
self.tobeupd = str(i)
print(self.tobeupd)
input('Write something: ')
class updApp(App):
def build(self):
return MyBox()
if __name__ == '__main__':
updApp().run()
*. Kilovolt
<MyBox>:
orientation: 'horizontal'
cols: 2
Label:
text: root.tobeupd
Button:
text: 'Start Update'
on_release: root.upd_ltxt()
While the βprint statement updates the shell regularly, the label text is only updated at the end of the for-loop. Can someone explain to me why Qiwi works this way and how can I overcome this problem?
EDIT: According to PM2Ring and Gugas, I changed the code to avoid the sleep function. The problem remains if I ask the user to enter something before the cycle continues. Values ββare updated in the shell, but not on the shortcut.