【问题标题】:Label not being displayed in kivy screen with Navigation drawer带有导航抽屉的 kivy 屏幕中未显示标签
【发布时间】:2020-05-10 15:59:00
【问题描述】:

在这里,我正在尝试构建一个具有导航栏的应用程序。当我单击这些项目时,导航栏有 OneLineListItem,屏幕会发生变化,但标签没有出现。我还尝试在布局中添加多个按钮,它工作正常。但是当我添加不显示的标签。

以下是我使用的kv语言代码:-

#:import FadeTransition kivy.uix.screenmanager.FadeTransition
# Menu item in the DrawerList list.
<ItemDrawer>:
    theme_text_color: "Custom"
    on_release: self.parent.set_color_item(self)

IconLeftWidget:
    id: icon
    icon: root.icon
    theme_text_color: "Custom"
    text_color: root.text_color


<ContentNavigationDrawer>:
    orientation: "vertical"
    padding: "8dp"
    spacing: "8dp"

AnchorLayout:
    anchor_x: "left"
    size_hint_y: None
    height: avatar.height

    Image:
        id: avatar
        size_hint: None, None
        size: "56dp", "56dp"
        source: "data/logo/kivy-icon-256.png"

MDLabel:
    text: "Voice Cloning Tool"
    font_style: "Button"
    size_hint_y: None
    height: self.texture_size[1]

MDLabel:
    text: "MENU"
    font_style: "Caption"
    size_hint_y: None
    height: self.texture_size[1]

ScrollView:

    DrawerList:
        OneLineListItem:
            text:'Home'
            on_release:app.root.current='home_screen'

        OneLineListItem:
            text:'Record Voice'
            on_release:app.root.current='rec_screen'
        OneLineListItem:

            text:'Help'
        OneLineListItem:

            text:'About'
        OneLineListItem:
            text:'Contact Us'
ScreenManagement:
    transition:FadeTransition()
    HomeScreen:
    RecordScreen:
    AboutScreen:
    ContactUSScreen:

<HomeScreen>:
    name:'home_screen'

    NavigationLayout:

        ScreenManager:

            Screen:
                SliderWin

                BoxLayout:
                    orientation: 'vertical'

                    MDToolbar:
                        title: "Explore Voice cloning Tool"
                        elevation: 10
                        left_action_items: [['menu', lambda x: nav_drawer.toggle_nav_drawer()]]

                    Widget:




    MDNavigationDrawer:
            id: nav_drawer

            ContentNavigationDrawer:
                id: content_drawer

<RecordScreen>:
    name:'rec_screen'

    NavigationLayout:

        ScreenManager:

            Screen:


                BoxLayout:
                    orientation: 'vertical'

                    MDToolbar:
                        title: "Explore Voice cloning Tool"
                        elevation: 10
                        left_action_items: [['menu', lambda x: nav_drawer.toggle_nav_drawer()]]
                    Button:
                        text:'Hello World'
                        size_hint:0.5,0.1
                        pos_hint:{'x':0.5,'y':0.5}
                    Button:
                        text:'Hello World'
                        size_hint:0.5,0.1
                        pos_hint:{'x':0.5,'y':0.5}



        MDNavigationDrawer:
            id: nav_drawer

            ContentNavigationDrawer:
                id: content_drawer

【问题讨论】:

    标签: python-3.x kivy kivy-language


    【解决方案1】:

    我在这里是白痴。我忘记了标签默认为白色的事实。这里我的背景也是白色的,这就是它没有显示的原因。 我将标签的颜色更改为其他颜色并显示。以下是更改后的代码:-

    #:import FadeTransition kivy.uix.screenmanager.FadeTransition
    # Menu item in the DrawerList list.
    <ItemDrawer>:
        theme_text_color: "Custom"
        on_release: self.parent.set_color_item(self)
    
        IconLeftWidget:
            id: icon
            icon: root.icon
            theme_text_color: "Custom"
            text_color: root.text_color
    
    
    <ContentNavigationDrawer>:
        orientation: "vertical"
        padding: "8dp"
        spacing: "8dp"
    
        AnchorLayout:
            anchor_x: "left"
            size_hint_y: None
            height: avatar.height
    
            Image:
                id: avatar
                size_hint: None, None
                size: "56dp", "56dp"
                source: "data/logo/kivy-icon-256.png"
    
        MDLabel:
            text: "Voice Cloning Tool"
            font_style: "Button"
            size_hint_y: None
            height: self.texture_size[1]
    
        MDLabel:
            text: "MENU"
            font_style: "Caption"
            size_hint_y: None
            height: self.texture_size[1]
    
        ScrollView:
    
            DrawerList:
                OneLineListItem:
                    text:'Home'
                    on_release:app.root.current='home_screen'
    
                OneLineListItem:
                    text:'Record Voice'
                    on_release:app.root.current='rec_screen'
                OneLineListItem:
    
                    text:'Help'
                OneLineListItem:
    
                    text:'About'
                OneLineListItem:
                    text:'Contact Us'
    ScreenManagement:
        transition:FadeTransition()
        HomeScreen:
        RecordScreen:
        AboutScreen:
        ContactUSScreen:
    
    <HomeScreen>:
        name:'home_screen'
    
        NavigationLayout:
    
            ScreenManager:
    
                Screen:
                    SliderWin
    
                    BoxLayout:
                        orientation: 'vertical'
    
                        MDToolbar:
                            title: "Explore Voice cloning Tool"
                            elevation: 10
                            left_action_items: [['menu', lambda x: nav_drawer.toggle_nav_drawer()]]
    
                        Widget:
    
    
            MDNavigationDrawer:
                id: nav_drawer
    
                ContentNavigationDrawer:
                    id: content_drawer
    
    <RecordScreen>:
        name:'rec_screen'
    
        NavigationLayout:
    
            ScreenManager:
    
                Screen:
    
    
    
                    BoxLayout:
    
                        orientation: 'vertical'
    
                        MDToolbar:
                            title: "Explore Voice cloning Tool"
                            elevation: 10
                            left_action_items: [['menu', lambda x: nav_drawer.toggle_nav_drawer()]]
                        Label:
    
                            text:'Hello World'
                            size_hint:0.5,0.1
                            pos_hint:{'x':0.5,'y':0.5}
                            color:1,0,1,1
    
                        Button:
                            text:'Hello World'
                            size_hint:0.5,0.1
                            pos_hint:{'x':0.5,'y':0.5}
    
    
    
            MDNavigationDrawer:
                id: nav_drawer
    
                ContentNavigationDrawer:
                    id: content_drawer
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-05-30
      • 2018-12-16
      相关资源
      最近更新 更多