简体   繁体   中英

Python Kivy - Margin to outer layout

I'm trying to learn Kivy and am trying to create margins between inner and outer layouts. For the parent layout, the size_hint and pos_hint does what it should, but for the child layout, the margin functionality works only vertically, resulting in the following:

在此处输入图片说明

What am I doing wrong?

Code:

BoxLayout:
    size_hint: [.9, .9]
    pos_hint: { 'top' : .95, 'right': .95}
    canvas:
        Color:
            rgb: [.8, .8, .8]
        Rectangle:
            pos: self.pos
            size: self.size

    BoxLayout:
        size_hint: [.9, .9]
        pos_hint: { 'top' : .95, 'right': .95}
        canvas:
            Color:
                rgb: [.6, .6, .6]
            Rectangle:
                pos: self.pos
                size: self.size

I also think you can use the floating layout. But I guess that you want to do a design using padding and spacing here.

The code below will give padding and spacing like the image.

BoxLayout:
    size_hint: [.9, .9]
    pos_hint: { 'top' : .95, 'right': .95}

    # Add padding and spacing
    orientation: 'vertical'
    padding: 50
    spacing: 100

    canvas:
        Color:
            rgb: [.8, .8, .8]
        Rectangle:
            pos: self.pos
            size: self.size

    # Add New BoxLayout
    BoxLayout:
        canvas:
            Color:
                rgb: [.6, .6, .6]
            Rectangle:
                pos: self.pos
                size: self.size
    BoxLayout:
        canvas:
            Color:
                rgb: [.6, .6, .6]
            Rectangle:
                pos: self.pos
                size: self.size

Image of padding and spacing

你为什么使用 BoxLayout,它用于将多个小部件放在一个中,在这里你只需在他的画布中放置一个矩形并给他一个子小部件,我不确定但也许它会有所帮助,并且可能使根成为一个浮动布局。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM