Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/348.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python Kivy侧边栏+内容布局_Python_Kivy - Fatal编程技术网

Python Kivy侧边栏+内容布局

Python Kivy侧边栏+内容布局,python,kivy,Python,Kivy,我希望在我的kivy应用程序上有一个固定宽度的右侧边栏,上面有一系列按钮和一个主要的绘图区域,我不确定哪种方法是正确的(即,哪种布局),我目前的位置如下: layoutApp.py 和layoutApp.kv 产生: 问题在于大小是相对的,即右侧边栏宽度根据屏幕抓取/调整大小而变化,这不是预期的行为 谢谢 您可以设置侧边栏的宽度,然后使用ids使大按钮的宽度取决于此: BoxLayout: id: top_box orientation: 'vertical' BoxL

我希望在我的kivy应用程序上有一个固定宽度的右侧边栏,上面有一系列按钮和一个主要的绘图区域,我不确定哪种方法是正确的(即,哪种布局),我目前的位置如下:

layoutApp.py

和layoutApp.kv

产生:

问题在于大小是相对的,即右侧边栏宽度根据屏幕抓取/调整大小而变化,这不是预期的行为


谢谢

您可以设置侧边栏的宽度,然后使用
ids
使大按钮的宽度取决于此:

BoxLayout:
    id: top_box
    orientation: 'vertical'
    BoxLayout:
        Button:
            size_hint_x: None
            width: top_box.width - bottom_box.width
        BoxLayout:
            id: bottom_box
            orientation: 'vertical'
            size_hint_x: None
            width: 150
            Button:
            Button:
            Button:
            Button:

对@John_Anderson稍作修改,顶部对齐的按钮很薄:

BoxLayout:
    id: top_box
    orientation: 'vertical'
    BoxLayout:
        Button:
            size_hint_x: None
            width: top_box.width - bottom_box.width
        BoxLayout:
            padding: 4
            id: bottom_box
            orientation: 'vertical'
            size_hint_x: None
            width: 200
            spacing: 2
            Button:
                id: button_1
                background_normal: ''
                background_color: .2, .2, .2, 1
                text: 'Button 1'
                color: .6, .6, .6, 1
                size_hint_x: None
                size_hint_y: None
                width: 192
                height: 40
            Button:
                id: button_2
                background_normal: ''
                background_color: .2, .2, .2, 1
                text: 'Button 2'
                color: .6, .6, .6, 1
                size_hint_x: None
                size_hint_y: None
                width: 192
                height: 40
            Button:
                id: button_3
                background_normal: ''
                background_color: .2, .2, .2, 1
                text: 'Button 3'
                color: .6, .6, .6, 1
                size_hint_x: None
                size_hint_y: None
                width: 192
                height: 40
            Button:
                id: button_4
                background_normal: ''
                background_color: .2, .2, .2, 1
                text: 'Button 4'
                color: .6, .6, .6, 1
                size_hint_x: None
                size_hint_y: None
                width: 192
                height: 40
            Widget:


结果:

BoxLayout:
    id: top_box
    orientation: 'vertical'
    BoxLayout:
        Button:
            size_hint_x: None
            width: top_box.width - bottom_box.width
        BoxLayout:
            id: bottom_box
            orientation: 'vertical'
            size_hint_x: None
            width: 150
            Button:
            Button:
            Button:
            Button:
BoxLayout:
    id: top_box
    orientation: 'vertical'
    BoxLayout:
        Button:
            size_hint_x: None
            width: top_box.width - bottom_box.width
        BoxLayout:
            padding: 4
            id: bottom_box
            orientation: 'vertical'
            size_hint_x: None
            width: 200
            spacing: 2
            Button:
                id: button_1
                background_normal: ''
                background_color: .2, .2, .2, 1
                text: 'Button 1'
                color: .6, .6, .6, 1
                size_hint_x: None
                size_hint_y: None
                width: 192
                height: 40
            Button:
                id: button_2
                background_normal: ''
                background_color: .2, .2, .2, 1
                text: 'Button 2'
                color: .6, .6, .6, 1
                size_hint_x: None
                size_hint_y: None
                width: 192
                height: 40
            Button:
                id: button_3
                background_normal: ''
                background_color: .2, .2, .2, 1
                text: 'Button 3'
                color: .6, .6, .6, 1
                size_hint_x: None
                size_hint_y: None
                width: 192
                height: 40
            Button:
                id: button_4
                background_normal: ''
                background_color: .2, .2, .2, 1
                text: 'Button 4'
                color: .6, .6, .6, 1
                size_hint_x: None
                size_hint_y: None
                width: 192
                height: 40
            Widget: