Reputation: 3415
I've been trying for quite a while to figure out how to update labels using python/kivy, I can set the label, but I can't get it to update after it's been set. This is my python code:
class MenuScreen(Screen):
status = StringProperty()
status = 'Text_Status' # This works.
def updatelabel(self, ):
# When I call this function, this does not update the label.
self.status='Text_status no.2'
And this is my .kv file
Label:
id: status
font_size: 12
text: root.status
size_hint: 0.25, 0.05
color: 1,1,1,1
pos_hint: {"x": 0.75, 'y':0.95}
I've been trying to figure this out for ages and I can't seem to get it.
Using kivy 1.9.0
Any help would be greatly appreciated.
Upvotes: 0
Views: 407
Reputation: 3415
I finally stumbled upon the answer:
status = StringProperty()
def __init__(self, **kwargs):
super(MenuScreen, self).__init__(**kwargs)
self.status='Text_status'
def updatelabel(self):
print("Trying to update label")
self.status='Text_status no.2' # When I call this function, this does not update the label.
This now works fine. I was missing the def __init__ function.
Upvotes: 1