Change screen by python file in kivy

1

I need to change the screen inside the .py file, I can not do that for .kv because I have to use ButtonBehavior and it does not work on .kv .

    from kivy.app import App
    from kivy.uix.boxlayout import BoxLayout
    from kivy.uix.button import ButtonBehavior
    from kivy.uix.image import Image, AsyncImage
    from kivy.uix.screenmanager import ScreenManager, Screen

    import json
    import requests


    class TelaInicio(Screen):
        pass


    class TelaLigas(Screen):
        def on_enter(self, *args):
            url = requests.get('http://127.0.0.1:8000/api/ligas')
            res = json.loads(url.text)
            for i in res:
                self.ids.ligas.add_widget(ListaLigas(ligas=i['imagem']))


    class TelaTorneios(Screen):
        pass


    class ListaLigas(BoxLayout, ButtonBehavior, Image):
        def __init__(self, ligas, manager=None, **kwargs):
            super(ListaLigas, self).__init__(**kwargs)
            self.manager = manager
            self.l = str(ligas)
            self.add_widget(AsyncImage(source=self.l))

        def on_press(self):
            print('ok')
            self.manager.troca_tela_torneios()


    class Manager(ScreenManager):
        def __init__(self, **kwargs):
            super(Manager, self).__init__(**kwargs)
            self.lista_ligas = ListaLigas(self)

        def troca_tela_torneios(self):
            self.current = 'tela_torneios'

        def troca_tela_ligas(self):
            self.current = 'tela_ligas'

        def troca_tela_inicio(self):
            self.current = 'tela_inicio'


    class Main(App):
        def build(self):
            return Manager()


    if __name__ == '__main__':
        Main().run()

The error:

  

File "/home/marcelo/PycharmProjects/EAnimaApp/main.py", line 36, in   on_press        self.manager.troca_tela_torneios () AttributeError: 'NoneType' object has no attribute 'change_to_tories'

    
asked by anonymous 12.07.2018 / 07:44

0 answers