I am new to the library kivy for Python. I found the additional library kivy-md which has very good looking ui elements. At the moment I want to create many MDTextField widgets from a dictionary variable e.g.
# text_fields.py
text_fields = {
"text_field1": {
"key": 0,
"self": "text_field1",
"hint_text": "Textfield 1",
"helper_text": "This is textfield 1",
},
"text_field2": {
"key": 1,
"self": "text_field2",
"hint_text": "Textfield 2",
"helper_text": "This is textfield 2",
}
}
From this variable, I want to create widgets in the kv file that look like
GridLayout:
MDTextField:
id: text_field1
hint_text: text_fields["text_field1"]["hint_text"]
helper_text: text_fields["text_field1"]["helper_text"]
helper_text_mode: "on_focus"
on_text_validate: app.on_text_validate(text_fields["text_field1"]["self"])
MDTextField:
id: text_field2
hint_text: text_fields["text_field2"]["hint_text"]
helper_text: text_fields["text_field2"]["helper_text"]
helper_text_mode: "on_focus"
on_text_validate: app.on_text_validate(text_fields["text_field2"]["self"])
I see two challenges in this problem that I am not able to solve. The first is how to parse the id values from the dictionary strings and the second problem is that I do not know how to loop over kivy widgets in a kv file.
Is there a way to achieve what I want?
