Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python Kivy - Margin to outer layout

Tags:

python

kivy

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:

enter image description here

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
like image 337
Daniel Slätt Avatar asked Oct 19 '25 14:10

Daniel Slätt


1 Answers

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

like image 112
Masumi Morishige Avatar answered Oct 22 '25 03:10

Masumi Morishige



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!