'Updating a label from increase and decrease buttons kivy

Hi I would like to update a label when pressing the + or - buttons, they were created in py file in a for loop. My app has multiple screens with the same strucure also created with a for loop.

class CustomScreen2(Screen):

def __init__(self, **kwargs):
    super(CustomScreen2, self).__init__(**kwargs)
    scroll=ScrollView()
    layout = GridLayout(cols=1, size_hint_y=None, height= 1000)
    layout.add_widget(Label(text=self.name, font_size=20))
    for i in range(1,13):
       navig = GridLayout(cols=5)
       txt='Exemplo_%d' %i
       navig.add_widget(Label(text=txt))
       for i in range(4):
           coluna=GridLayout(cols=1, rows=3)
           btn_soma= Button(text="+")
           self.label=Label(text="0")
           btn_sub= Button(text="-")
           btn_soma.bind(on_press=self.soma)
           btn_sub.bind(on_press=self.sub)
           coluna.add_widget(btn_soma)
           coluna.add_widget(self.label)
           coluna.add_widget(btn_sub)

           navig.add_widget(coluna)

       layout.add_widget(navig)
    scroll.add_widget(layout)
    self.add_widget(scroll)

def soma(self,*args):
    pass
def sub(self):
    pass

class ScreenManagerApp(App):
def build(self):
    root = ScreenManager()
    root.add_widget(Homepage(name='home'))
    for i in range(7):
        for j in range(7):
            root.add_widget(CustomScreen2(name='Registo_%d_%d' % (i, j) ))

    return root


Solution 1:[1]

To change text of a Label, all you've got to do is:

  1. Give the Label an ID.
  2. In the function that will switch the Label's text, do self.ids.NAME_OF_LABEL'S_ID.text = NEW_TEXT

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 mohammad.alqashqish