Skip to content

CBoxLayout

This component is equivalent to the BoxLayout component.

Properties

Background color

You can change the background color of the BoxLayout by using the bg_color property.

main.py
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
from kivy.app import App
from kivy.lang import Builder
from kivy_widgets.boxlayout import CBoxLayout


kv = Builder.load_string("""
CBoxLayout:
    bg_color: blue_900
""")


class MainApp(App):
    def build(self):
        return kv


MainApp().run()

BoxLayout background color

Orientation

By default, the BoxLayout will stack widgets on the horizontal orientation, which means the widgets will be stacked horizontally, from left to right.

You can change it to vertical by setting the orientation property to vertical.

main.py
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
from kivy.app import App
from kivy.lang import Builder
from kivy_widgets.boxlayout import CBoxLayout
from kivy_widgets.button import CButton

kv = Builder.load_string("""
CBoxLayout:
    CButton:
        text: 'Button 1'
        bg_color: red_400
        font_color: white
    CButton:
        text: 'Button 2'
        bg_color: sky_400
        font_color: white
    CButton:
        text: 'Button 3'
        bg_color: green_400
        font_color: white
"""
)


class MainApp(App):
    def build(self):
        return kv


MainApp().run()

Horizontal Box Layout

main.py
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
from kivy.app import App
from kivy.lang import Builder
from kivy_widgets.boxlayout import CBoxLayout
from kivy_widgets.button import CButton

kv = Builder.load_string("""
CBoxLayout:
    orientation: 'vertical'
    CButton:
        text: 'Button 1'
        bg_color: red_400
        font_color: white
    CButton:
        text: 'Button 2'
        bg_color: sky_400
        font_color: white
    CButton:
        text: 'Button 3'
        bg_color: green_400
        font_color: white
"""
)


class MainApp(App):
    def build(self):
        return kv


MainApp().run()

Vertical Box Layout