0

I'm trying to make the button click on_release: app.proximo () have the action to go to the next card MDFloatLayout, but I'm not getting it, could someone help me how could it work?

Below the main.py file, where to start the app, main.kv file, where is the main app and finally the dashboard.kv file where I am calling my card inside the app

from kivymd.app import MDApp
from kivy.lang import Builder
from kivy.uix.screenmanager import Screen

class DashBoard(Screen):
    pass
class FirstScreen(Screen):
    pass

class Lavanderia(MDApp):
    def build(self):
        self.title="Texto Titulo"
        self.theme_cls.primary_palette = "LightBlue"
        return Builder.load_file("main.kv")

    def proximo(self):
        self.root.ids.carousel.load_next(mode="proximo")# Próximo Card
    def fecharApp(self):
        self.stop()# Fecha Aplicativo
Lavanderia().run()



#:import rgba kivy.utils.get_color_from_hex
#: include dashboard.kv
#: include firstscreen.kv
NavigationLayout:
    id: nav_layout
    ScreenManager:
        Screen:
            BoxLayout:
                orientation:'vertical'
                MDToolbar:
                    title: app.title
                    elevation:10
                    left_action_items:[["menu", lambda x: nav_drawer.set_state()]]
                ScreenManager:
                    id: screen_manager
                    DashBoard:
                        id:dashboard
                        name:"dashboard"
                    FirstScreen:
                        id:first_screen
                        name:"first_screen"
    MDNavigationDrawer:
        id: nav_drawer
        BoxLayout:
            orientation:'vertical'
            padding:"8dp"
            spacing:"8dp"
            Image:
                pos_hint:{"x":.24,"y":.0}
                size_hint: None, None
                size:dp(146), dp(158)
                source:"images/logo.png"  
            ScrollView:
                MDList:
                    OneLineIconListItem:
                        text:"Tela 1"
                        on_release:
                            screen_manager.current = "dashboard"
                            nav_drawer.set_state()
                        IconLeftWidget:
                            icon:"dishwasher"
                    OneLineIconListItem:
                        text:"Tela 2"
                        on_release:
                            screen_manager.current = "first_screen"
                            nav_drawer.set_state()
                        IconLeftWidget:
                            icon:"dishwasher"



<DashBoard>:
    MDFloatLayout:
        MDCard:
            size_hint: dp(.45), dp(.8)
            pos_hint:{"center_x": .5, "center_y": .5}
            Carousel:
                id:carousel
                MDFloatLayout:
                    MDTextField:
                        hint_text:"Texto 1"
                        size_hint_x:dp(.8)
                        pos_hint:{"center_x": .5, "center_y": .48}
                    MDRaisedButton:
                        text: "Proximo"
                        size_hint_x:dp(.8)
                        pos_hint:{"center_x":.5,"center_y":.2}
                        on_release: app.proximo() # Proximo step
                MDFloatLayout:
                    MDLabel:
                        text:"Texto Final Conclusão"
                        theme_text_color:"Custom"
                        bold:True
                        pos_hint:{"center_x":.68,"center_y":.5}
                        font_style:"H5"
                    MDRaisedButton:
                        text: "Fechar Aplicativo"
                        text_color:rgba("#00FF69")
                        size_hint_x:dp(.8)
                        pos_hint:{"center_x":.5,"center_y":.4}
                        md_bg_color:rgba("#333333")
                        on_release: app.fecharApp() #fechar Aplicativo
Gbyteinfo
  • 1
  • 1

1 Answers1

0

You are trying to ger the carrousel through the root screen, but it is inside the dashboard screen.

So you will have to navigate there first, and only then you can call your function.

def proximo(self):
    dashboard = self.root.ids.dashboard
    carousel = dashboard.ids.carousel
    carousel.load_next(mode="proximo")
    # Same as
    # self.root.ids.dashboard.ids.carousel.load_next(mode="proximo")
Arthur Pereira
  • 1,509
  • 2
  • 8
  • 18