Alignment
Alignment
#
Defines an alignment relative to the center.
x
#
x: Number
Represents the horizontal distance from the center.
It's value ranges between -1.0
and 1.0
inclusive.
y
#
y: Number
Represents the vertical distance from the center.
It's value ranges between -1.0
and 1.0
inclusive.
BOTTOM_CENTER
#
Represents the bottom center and is equivalent to Alignment(0.0, 1.0)
.
BOTTOM_LEFT
#
Represents the bottom left corner and is equivalent to Alignment(-1.0, 1.0)
.
BOTTOM_RIGHT
#
Represents the bottom right corner and is equivalent to Alignment(1.0, 1.0)
.
CENTER_LEFT
#
Represents the center left and is equivalent to Alignment(-1.0, 0.0)
.
CENTER_RIGHT
#
Represents the center right and is equivalent to Alignment(1.0, 0.0)
.
TOP_CENTER
#
Represents the top center and is equivalent to Alignment(0.0, -1.0)
.
TOP_LEFT
#
Represents the top left corner and is equivalent to Alignment(-1.0, -1.0)
.
TOP_RIGHT
#
Represents the top right corner and is equivalent to Alignment(1.0, -1.0)
.
Examples#
Example 1#
import flet as ft
def main(page: ft.Page):
page.title = "Containers with different alignments"
page.add(
ft.Row(
controls=[
ft.Container(
content=ft.ElevatedButton("Center"),
bgcolor=ft.Colors.AMBER,
padding=15,
alignment=ft.Alignment.CENTER,
width=150,
height=150,
),
ft.Container(
content=ft.ElevatedButton("Top left"),
bgcolor=ft.Colors.AMBER,
padding=15,
alignment=ft.Alignment.TOP_LEFT,
width=150,
height=150,
),
ft.Container(
content=ft.ElevatedButton("-0.5, -0.5"),
bgcolor=ft.Colors.AMBER,
padding=15,
alignment=ft.alignment.Alignment(-0.5, -0.5),
width=150,
height=150,
),
]
)
)
ft.run(main)