访问子布局中的小部件

时间:2020-03-18 03:11:41

标签: python kivy dropdown

这是我的代码。我有一个带有两个屏幕的屏幕管理器。

  • 屏幕1:登录
  • 屏幕2:选项卡式选项

在屏幕2中,我有一个下拉窗口小部件,我想在其中加载一些默认值。但是我无法访问相同的ID。

Builder.load_string("""

<TACLogin>
   FloatLayout:

      MDToolbar:
        title: "TEST"
        pos_hint: {"x":0.001, "y":0.9}

      MDRectangleFlatIconButton:
        id: tac_screen1_next_id
        icon: "page-next-outline"
        font_size: '20sp'            
        font_name: 'fonts/prox_nova.ttf'
        md_bg_color:  0, 0.502, 0.502, 1       
        text_color: 1,1,1,1
        text: 'Login'
        on_press: root.manager.current = 'tacconfig'
        size_hint: None, None
        size: dp(100), dp(30) 
        pos_hint: {"x":0.7, "y":0.2}
<TACConfig>
    BoxLayout:
      orientation:"vertical" 
      MDToolbar:
        title: "Taxonomy Administration Console"
        specific_text_color: app.theme_cls.accent_color

      MDTabs:
        id: android_tabs
        text_color_normal: 1,1,1,1
        Tab:
            text:"Home"
            text_color_normal: 1,1,1,1
            MDLabel:
                color: 0,0,0,1
                font_size: '20sp'
                font_name: 'fonts/prox_nova.ttf'

                pos_hint: {"x":0.4, "y":0.1}
                text:'WELCOME ADMIN'
        Tab:
            text_color_normal: 1,1,1,1
            text:"Configure User"
            TACUserConfig:

        Tab:
            text_color_normal: 1,1,1,1
            text:"Configure DataSource"
            TACScreen1:

        Tab:
            text_color_normal: 1,1,1,1
            text:"Exit"                    

 <TACUserConfig>

FloatLayout:
    id: ucScreen_id        
    MDLabel:            
        color: 0,0,0,1
        font_size: '15sp'
        font_name: 'fonts/prox_nova.ttf'
        text:'Select User Type'
        pos_hint:{'center':(0.7,0.7)}
        size_hint:0.8,1.4
    MDDropDownItem:
        id: user_type            
        pos_hint:{"x":0.5, "y":0.68}         
        dropdown_bg: [1, 1, 1, 1]
""")

这是我的python代码

class TACLogin(Screen, MDApp):
def __init__(self, **kwargs):
    super(TACLogin, self).__init__(**kwargs)

class TACUserConfig(Screen, MDApp):
def __init__(self, **kwargs):
    super(TACUserConfig, self).__init__(**kwargs)
    print(self.ids)

def on_start(self):
    self.ids.ucScreen_id.ids.user_type.items = ["Business User", "Admin User"]

sm = ScreenManager()
sm.add_widget(TACLogin(name='taclogin'))
sm.add_widget(TACConfig(name='tacconfig'))
sm.add_widget(TACUserConfig(name='tacuserconfig'))

class TestApp(MDApp):

def build(self):
    self.theme_cls.primary_palette = "Teal"
    return sm


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

我正在尝试向下拉列表中添加值,on_start函数根本未触发,并且我无法访问下拉user_type的ID。有人可以帮我吗?

0 个答案:

没有答案