MainAxisAlignment
MainAxisAlignment
#
Bases: Enum
How the children should be placed along the main axis.
CENTER = 'center'
#
Place the children as close to the middle of the main axis as possible.
END = 'end'
#
Place the children as close to the end of the main axis as possible.
SPACE_AROUND = 'spaceAround'
#
Place the free space evenly between the children as well as half of that space before and after the first and last child.
SPACE_BETWEEN = 'spaceBetween'
#
Place the free space evenly between the children.
SPACE_EVENLY = 'spaceEvenly'
#
Place the free space evenly between the children as well as before and after the first and last child.
START = 'start'
#
Place the children as close to the start of the main axis as possible.
Usage example#
import flet as ft
def main(page: ft.Page):
def items(count):
items = []
for i in range(1, count + 1):
items.append(
ft.Container(
content=ft.Text(value=str(i)),
alignment=ft.alignment.center,
width=50,
height=50,
bgcolor=ft.Colors.AMBER_500,
)
)
return items
def column_with_alignment(align: ft.MainAxisAlignment):
return ft.Column(
[
ft.Text(str(align), size=10),
ft.Container(
content=ft.Column(items(3), alignment=align),
bgcolor=ft.Colors.AMBER_100,
height=400,
),
]
)
page.add(
ft.Row(
[
column_with_alignment(ft.MainAxisAlignment.START),
column_with_alignment(ft.MainAxisAlignment.CENTER),
column_with_alignment(ft.MainAxisAlignment.END),
column_with_alignment(ft.MainAxisAlignment.SPACE_BETWEEN),
column_with_alignment(ft.MainAxisAlignment.SPACE_AROUND),
column_with_alignment(ft.MainAxisAlignment.SPACE_EVENLY),
],
spacing=30,
alignment=ft.MainAxisAlignment.START,
)
)
ft.run(main)