i am making an app to multiply 2 matrix. for that i created the user interface but cant figure it out how to get the user input in my python file, so i can do operations there.
here's my kivy file
#: import MDTextField kivymd.uix.textfield.MDTextField
<MyApp>:
NavigationLayout:
ScreenManager:
Screen:
name: "screen1"
GridLayout:
cols: 4
padding: 30
spacing: 20
size: root.width * 0.4, root.height * 0.8
row_force_default: True
row_default_height: 30
pos_hint: {'center_x': 0.5,'center_y':0.55}
size_hint: (None, None)
size: self.minimum_size
top: self.height
on_parent:
for i in range(16): self.add_widget(MDTextField(hint_text= 'sc', helper_text= 'hello', size_hint_x= None, width = 40))
MDRectangleFlatButton:
text: 'back'
pos_hint: {'center_x': 0.5, 'center_y': 0.4}
on_release:
app.find_multiply()
since my MDTextField is inside a for loop, so i can't use an id there because from that i will get all 16 text field with the same id. how do i get my all 16 textfield input inside the app.find_multiply funcition in my python file, so i can perform operation there.
Store references to your text fields, and access them later to do what you want.
I would delete your
on_parent
, replace theGridLayout
with your own classMyGridLayout(GridLayout):
, and have that class do:Then later when you want to access them, you can iterate through e.g.
entered_numbers = [int(field.text) for field in self.text_field]
.Of course that's just a basic example, in reality you'll want error checking etc.