D
D
Dirollo2020-07-24 15:27:20
Python
Dirollo, 2020-07-24 15:27:20

How to get access to MDTabs in .kv by id (everything is complicated)?

Koo, I have a conditional code:

from kivy.lang import Builder
from kivymd.app import MDApp
from kivymd.uix.tab import MDTabsBase
from kivy.uix.floatlayout import FloatLayout

root_kv = """
BoxLayout:
    orientation: "vertical"

    MDToolbar:
        id: toolbar
        title: "Test MDBottomNavigation"
        md_bg_color: app.theme_cls.primary_color

    MDBottomNavigation:
        id: panel

        MDBottomNavigationItem:
            name: "files1"
            text: "Python"
            icon: "language-python"

            BoxLayout:
                orientation: "vertical"
                size_hint_y: None
                height: self.minimum_height
                spacing: dp(10)
                pos_hint: {"center_x": .5, "center_y": .5}

                MDLabel:
                    font_style: "Body1"
                    theme_text_color: "Primary"
                    text: "Toggle to set custom panel color"
                    halign: "center"

        MDBottomNavigationItem:
            name: "files2"
            text: "Settings"
            icon: "settings"
            
            MDTabs:
            	id: tabs
"""


class Tab(MDTabsBase, FloatLayout):
  pass

class MainApp(MDApp):
    def __init__(self, **kwargs):
        self.title = "KivyMD Examples - Bottom Navigation"
        super().__init__(**kwargs)

    def build(self):
        w1 = self.root.ids.panel.tabs.add_widget(Tab(text="loo"))
        self.root = Builder.load_string(root_kv)


if __name__ == "__main__":
    MainApp().run()


I need to be able to do what I want in the w1 variable, but how do I access the MDTabs: tabs id?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question