Access functions within classes in kivy + python

Asked

Viewed 535 times

1

This is the file . py

class Tela():
    pass
class teste():
    def chama(self):
        pass
    def save_d(self):
        pass
    
class Prg(App):
    def build(self):
        return Tela()
    
Prg().run()

This is the file . Kv

<Tela>:
    Button:
        on_release: O qu colocar aqui para acessar a função chama()
  • Provide a minimum, complete and verifiable example.

  • All right, I edited.

1 answer

1

With the app prefix you can access the main class methods.

prg.Kv

<Tela>:
    Button:
        on_release: app.teste.chama()

Prg.py

class Tela(Widget):
    pass
class teste():
    def chama(self):
        print("chama")
        pass
    def save_d(self):
        pass

class Prg(App):
    def build(self):
        self.teste = teste()
        return Tela()

Prg().run()
  • 1

    I understood, I edited the question and wanted to know, in case I need to access another class, for example a class Teste1() I tried on_release: app.teste1.chama() did not work. I wanted to understand how to access several classes. Thanks

  • the new classes must be defined in the Prg class

Browser other questions tagged

You are not signed in. Login or sign up in order to post.