To access the elements in a simple way, you must set the id, in this case I will put one on the TextInput associated with the numerical input, you should also put a filter to accept only numerical values:
TextInput: id: number_input text: root.col_data4 width: 300 input_filter: 'int'
Then the test() method boils down to the following:
class User(Screen): total_value = ObjectProperty(None) def add_more(self): self.ids.rows.add_row() def test(self): rows = self.ids.rows total = 0 for row in rows.children: text = row.ids.number_input.text total += int(text) if text != "" else 0
In order to be able to update the values automatically, we will associate the text change with the function, and in it we will call test() , in order to access the test, we must put the identifier on the screen:
User: id: user total_value: total_value [...]
to access the screen from App.get_running_app() :
class Row(BoxLayout): button_text = StringProperty("") col_data3 = StringProperty("") col_data4 = StringProperty("") def __init__(self, *args, **kwargs): super(Row, self).__init__(*args, **kwargs) self.ids.number_input.bind(text=self.on_text) def on_text(self, text_input, value): App.get_running_app().root.test()
The code:
demo.py
from kivy.uix.screenmanager import Screen from kivy.app import App from kivy.lang import Builder from kivy.core.window import Window from kivy.uix.boxlayout import BoxLayout from kivy.properties import BooleanProperty, ListProperty, StringProperty, ObjectProperty, NumericProperty from kivy.uix.textinput import TextInput from kivy.uix.button import Button Window.clearcolor = (0.5, 0.5, 0.5, 1) Window.size = (500, 400) class User(Screen): total_value = ObjectProperty(None) def add_more(self): self.ids.rows.add_row() def test(self): rows = self.ids.rows total = 0 for row in rows.children: text = row.ids.number_input.text total += int(text) if text != "" else 0 self.total_value.text = str(total) class Row(BoxLayout): button_text = StringProperty("") col_data3 = StringProperty("") col_data4 = StringProperty("") def __init__(self, *args, **kwargs): super(Row, self).__init__(*args, **kwargs) self.ids.number_input.bind(text=self.on_text) def on_text(self, text_input, value): App.get_running_app().root.test() class Rows(BoxLayout): row_count = 0 def __init__(self, **kwargs): super(Rows, self).__init__(**kwargs) self.add_row() def add_row(self): self.row_count += 1 self.add_widget(Row(button_text=str(self.row_count))) class Test(App): def build(self): self.root = Builder.load_file('demo.kv') return self.root if __name__ == '__main__': Test().run()
demo.kv
<Row>: size_hint_y: None height: self.minimum_height height: 40 Button: text: root.button_text size_hint_x: None top: 200 TextInput: text: root.col_data3 width: 300 TextInput: id: number_input text: root.col_data4 width: 300 input_filter: 'int' <Rows>: size_hint_y: None height: self.minimum_height orientation: "vertical" User: id: user total_value: total_value BoxLayout: orientation: "vertical" padding : 20, 5 BoxLayout: orientation: "horizontal"