Hello everyone!
I come to you because I am at the end of my rope. I kept on trying, persevered through a week of researching and trying everything I could find. I read the API docs, the tutorials, everything on SO I could find and tried approaches from 3 different kivy books. I just don't get it. I must be missing something.
I attach 4 files:
- main.py: named as such for use with buildozer
- words.txt: the dictionary I am using to match words
- words.kv: very simple interface
- logic.py: farming out some letter logic
Long story short, I just can't get 'scorelabel' to update automatically. It does work when I make a 4th button calling an 'update label text' function but that's not the point of the app or the label.
You may notice some peculiarities in the app....those are the signs of someone who doesn't know that much about how data should flow in kivy apps, it's all a bit hacky. It works though and I have managed to avoid global variables (yay!)
Here are some of the things I have tried:
- call " self.ids.scorelabel.text = self.a.thedict['score'] " in every way imaginable. I have called it in every place of every method, made it its own method and called it from another method, called it from outside the class, everything. Does nothing. Neither error nor anything else.
- printed self.ids.scorelabel.text to the console. Believe it or not, Kivy tells me the text of the label is in fact = self.a.thedict['score'] after updating it. What?? How is that possible? How can the text attribute of a label be something different from what is displayed?
- added " scorelabel = ObjectProperty() " in Root(), makes no difference
- tried binding a new variable called " scorestr " to any changes in the score when score updates. This fires correctly and catches the correct values, as you will see from the associated print statement in line 68. Makes no difference.
- tried setting the text property in the .kv file to the score variable....that just turns it into 0 at the beginning and after that nothing changes
- tried creating an 'update' method associated with 'on_press' and 'on_release' in the buttongrid, no difference
- same for 'on_touch_down' or 'on_touch_up'
- created a myriad different methods all of which could access 'score' just fine and return it straight to the label.text attribute, at which point the label does nothing again
I have tried many more really random things that I have seen from similar discussions here or on SO, but it seems as though most people are just struggling with the concept of bind() or the different properties. I don't think I have an issue with that. I struggled getting reliable access to 'score' as well, but you may notice that I simply made it into a dictionary key in the App class and that works just fine....even though it feels a bit hacky
There must be something I am missing. Is there some problem with how and when or where labels are rendered? Should I add the label widget in python instead of the kv file? (That seems wrong....)
If anyone has the time to take a look at this I would be eternally grateful!