2

I have a label and a text input, and I wanna change it's text property by a variable on .py file. Here's the code:

Here's the .kv

<DefinicaoDeSaidas>:

    BoxLayout:

        orientation:'vertical'

        BoxLayout:

            orientation:'vertical'

            padding: 0,20,20,50

            Image:

                source:'exemplo.png'

            Label:

                text:'Escolha as missoes para a saida'
                font_size:40

            TextInput:

                id: ti

Here's the .py

class DefinicaoDeSaidas(Screen): 

    #get the values and everything

    #transformate a variable ('name') onto the ti.text property 

You can see all the code by the github repository: https://github.com/Enzodtz/FLL-Artificial-Inteligence

Enzo Dtz
  • 361
  • 1
  • 16

1 Answers1

2

Do not use id in the .py since it often leads to having a code like foo_object.ids.ti, instead you can expose it as a property:

<DefinicaoDeSaidas>:
    ti: ti # <---
    BoxLayout:
        orientation:'vertical'

        BoxLayout:
            orientation:'vertical'
            padding: 0,20,20,50

            Image:
                source:'exemplo.png'

            Label:
                text:'Escolha as missoes para a saida'
                font_size:40

            TextInput:
                id: ti

And then you can access using self from any method:

class DefinicaoDeSaidas(Screen): 
    # ...
    def foo_function(self, another_arguments):
        v = self.ti.text # get text
        self.ti.text = u # update text
eyllanesc
  • 235,170
  • 19
  • 170
  • 241