Skip to main content

Padding

Defines padding for all sides of a rectangle.

Properties

  • bottom - The padding value for the bottom side of the rectangle.
  • left - The padding value for the left side of the rectangle.
  • right - The padding value for the right side of the rectangle.
  • top - The padding value for the top side of the rectangle.

Methods

  • all - Applies the same padding to all sides.
  • only - Applies padding to the specified sides.
  • symmetric - Applies vertical padding to top and bottom sides and horizontal padding to left and right sides.
  • zero

Properties​

bottomclass-attributeinstance-attribute​

bottom: Number = 0

The padding value for the bottom side of the rectangle.

leftclass-attributeinstance-attribute​

left: Number = 0

The padding value for the left side of the rectangle.

rightclass-attributeinstance-attribute​

right: Number = 0

The padding value for the right side of the rectangle.

topclass-attributeinstance-attribute​

top: Number = 0

The padding value for the top side of the rectangle.

Methods​

allclassmethod​

all(value: Number) -> Padding

Applies the same padding to all sides.

onlyclassmethod​

only(
    left: Number = 0,
    top: Number = 0,
    right: Number = 0,
    bottom: Number = 0,
) -> Padding

Applies padding to the specified sides.

symmetricclassmethod​

symmetric(
    vertical: Number = 0, horizontal: Number = 0
) -> Padding

Applies vertical padding to top and bottom sides and horizontal padding to left and right sides.

zeroclassmethod​

zero() -> Padding

Examples​

Example 1​

play_arrowTry Online
import flet as ft


def container(title: str, padding: ft.Padding) -> ft.Container:
return ft.Container(
content=ft.Column(
controls=[
ft.Text(value=title, weight=ft.FontWeight.BOLD),
ft.Container(
bgcolor=ft.Colors.BLUE_GREY_100,
content=ft.Container(
bgcolor=ft.Colors.AMBER,
border=ft.Border.all(2, ft.Colors.RED),
padding=padding,
content=ft.Container(
bgcolor=ft.Colors.BLACK,
content=ft.Text("Content", color=ft.Colors.WHITE),
),
width=200,
height=200,
),
),
],
spacing=8,
)
)


def main(page: ft.Page):
page.title = "Containers with different padding"
page.padding = 20

page.add(
ft.SafeArea(
expand=True,
content=ft.Column(
scroll=ft.ScrollMode.AUTO,
controls=[
ft.Column(
spacing=22,
controls=[
container("Padding.all(10)", ft.Padding.all(10)),
container("Padding.all(20)", ft.Padding.all(20)),
container(
"Padding.symmetric(horizontal=10)",
ft.Padding.symmetric(horizontal=10),
),
container(
"Padding.symmetric(vertical=10)",
ft.Padding.symmetric(vertical=10),
),
container(
"Padding.only(left=10)", ft.Padding.only(left=10)
),
container("Padding.only(top=10)", ft.Padding.only(top=10)),
container(
"Padding.only(right=10)", ft.Padding.only(right=10)
),
container(
"Padding.only(bottom=10)", ft.Padding.only(bottom=10)
),
],
)
],
),
)
)


if __name__ == "__main__":
ft.run(main)
container