在Kivy中添加导航抽屉后不会显示背景图像

2024-04-27 04:29:11 发布

您现在位置:Python中文网/ 问答频道 /正文

所以我一直在创建一个应用程序,我想要一个导航抽屉,所以我添加了一个。然而,似乎我是一个皇家noob和不知何故使我的屏幕背景消失。我试过和你鬼混画布后它似乎工作,但它显示在屏幕前面的文本和按钮。我对python和Kivy非常陌生,所以请温柔地回答!你知道吗

FloatLayout:
    canvas:
        Rectangle:
            pos: self.pos
            size: self.size
            source: '9.png'


    NavigationDrawer:
        FloatLayout:
            orientation: 'vertical'
            canvas.before:
                Rectangle:
                    pos: self.pos
                    size: self.size
                    source: '9.png'
            Label:
                text: "Navigation Menu"
                pos_hint: {"y": 0.75}
                size_hint: 1, 0.2
                font_size: (root.width**2 + root.height**2) / 14**4
                font_name: "Product Sans.ttf"

            Button:
                text: "Example button"
                pos_hint: {"y":0.66}
                size_hint: 1.1, 0.06
                font_name: "OpenSans.ttf"
                on_release:
                    app.root.current = "Example"
                    root.manager.transition.direction = "right"

            Button:
                text: "Example button 2"
                pos_hint: {"y":0.1}
                size_hint: 1, 0.06
                font_name: "OpenSans.ttf"
                on_release:
                    app.root.current = "Example"
                    root.manager.transition.direction = "right"

        FloatLayout:
            size: root.width, root.height/2
            cols:2
            canvas:
                Rectangle:
                    pos: self.pos
                    size: self.size
                    source: '9.png' 
            Label:
                bold: True
                font_name: 'Product Sans.ttf'
                size_hint: 0.8,0.3
                pos_hint: {"x":0.1, "y":0.75}
                text: "Example"
                font_size: (root.width**2 + root.height**2) / 12**4

            Label:
                font_name: 'OpenSans.ttf'
                size_hint: 0.5,0.12
                pos_hint: {"x":0.08, "top":0.6}
                text: "Example "
                font_size: (root.width**2 + root.height**2) / 14**4

            TextInput:
                pos_hint: {"x":0.5, "top":0.58}
                size_hint: 0.4, 0.08
                id:Example
                multiline:False
                font_size: (root.width**2 + root.height**2) / 14**4

            RippleButton:
                font_name: 'OpenSans.ttf'
                text:"Exampler"
                pos_hint:{"x":0.3,"y":0.20}
                size_hint: 0.4, 0.1
                font_size: (root.width**2 + root.height**2) / 14**4
                on_release:
                    root.folder()

            RippleButton:
                text:"Example"
                font_name: 'OpenSans.ttf'
                pos_hint:{"x":0.3,"y":0.08}
                size_hint: 0.4, 0.1
                font_size: (root.width**2 + root.height**2) / 14**4
                on_release:
                    root.chrome()

            FloatButton:
                id: float_root
                size_hint: (None,None)
                btn_size: (50,50)
                size: (50,50)
                bg_color: (255,255,255,1)
                pos_hint: {'x': 0.01}
                RippleButton: 
                    text: float_root.text
                    markup: True
                    size_hint: (None,None)
                    size: float_root.btn_size
                    pos_hint: {'x': 0.05, 'y': 0.15}
                    background_normal: ''
                    background_color: (0,0,0,0)
                    canvas.before:
                        Ellipse:
                            size: self.size
                            pos: self.pos
                            source: 'LACB.png'
                    on_release:
                        app.root.current = "main"
                        root.manager.transition.direction = "right"

所以当我运行这个,我的背景图像消失,背景现在已经变成黑色。任何帮助都将不胜感激!你知道吗


Tags: textnameposselfsizereleaseonexample