So i am trying to build app to learn words in different languages. You create a folder(dict) with a word in one language as a key and as a value you put translated word.
Now ive made a PageLayout which creates as many buttons in pagelayout as many items i have in my dict and set as a text key()
py.file(This is class where i make buttons in pagelayout)
class CardGame(Screen):
page = ObjectProperty(None)
def cards(self):
with open('data.json') as file:
words = json.load(file)
name = self.manager.get_screen('before_game').ids.spinner.text
for key in words[name]:
self.ids.page.add_widget(Button(text=str(key)))
kivy file
<CardGame>:
page:page
GridLayout:
cols:1
GridLayout:
cols:1
Button:
text:'back'
on_press:root.back()
PageLayout:
border:100 <<<<<< Here it creates in this case 3 buttons
id:page
GridLayout:
cols:2
Button:
text:'left'
Button:
text:'right'
<RootWidget>:
LoginScreen:
name:'login_screen'
SignUpScreen:
name:'sign_up'
LoginSuccesfull:
name:'login_succesfull'
ForgotPassword:
name:'forgot_password'
CardGame:
name:'card_game'
on_pre_enter:self.cards()
on_leave:self.remove_buttons()
NewWord:
name:'new_word'
on_enter:self.spiner()
BeforeGame:
name:'before_game'
on_enter:self.spiner()
on_leave:self.clear_spinner()
Test:
name:'test'
on_pre_enter:self.testujemy()
dict:
{
"animals": {
"kot": "cat",
"pies": "dog",
"krowa": "cow"
},
"food": {
"jajko": "egg",
"szynka": "ham",
"mleko": "milk"
}
}
So in this scenario i choose which folder i want to open in Spinner and then after clicking button with game it switches to a Screen that will display PageLayout with all the buttons created with on_pre_enter in kv.file
But now problem starts for me since i want to implement function that after clicking Button(page in pagelayout) it will change its text to value from dict. So if a button(page) is 'pies', after clicking it i want to display 'dog' and so on. Basically you can switch button text between key and value from dict whenever you click button. And make it for every button ive created dynamically
I have no clue how to navigate each(page) button and then change its text value since it was made with a loop in py file. I was trying look for a solution with on_press but i fail while trying to refer to each page
Any help would be appreciated