Border
A border comprised of four sides: top, right, bottom, left.
Each side of the border is an instance of
BorderSide.
Properties
Methods
Properties
bottomclass-attributeinstance-attribute
bottom: BorderSide = field(
default_factory=lambda: BorderSide.none()
)Bottom side of the border.
leftclass-attributeinstance-attribute
left: BorderSide = field(
default_factory=lambda: BorderSide.none()
)Left side of the border.
rightclass-attributeinstance-attribute
right: BorderSide = field(
default_factory=lambda: BorderSide.none()
)Right side of the border.
topclass-attributeinstance-attribute
top: BorderSide = field(
default_factory=lambda: BorderSide.none()
)Top side of the border.
Methods
allclassmethod
all(
width: Number | None = None,
color: ColorValue | None = None,
side: BorderSide | None = None,
) -> BorderCreates a border whose sides are all the same.
If side is not None, it gets used and both width and color are ignored.
Parameters:
- width (Number | None, default:
None) - The side width. Used only whensideisNone. - color (ColorValue | None, default:
None) - The side color. Used only whensideisNone. - side (BorderSide | None, default:
None) - TheBorderSideto apply to all sides. If set, it has precedence overwidthandcolor.
Returns:
- A (Border) - class:
~flet.Borderwith identical sides.
copy
copy(
left: BorderSide | None = None,
top: BorderSide | None = None,
right: BorderSide | None = None,
bottom: BorderSide | None = None,
) -> BorderReturns a copy of this object with the specified properties overridden.
onlyclassmethod
only(
left: BorderSide | None = None,
top: BorderSide | None = None,
right: BorderSide | None = None,
bottom: BorderSide | None = None,
) -> BorderCreates a border with explicit sides.
Parameters:
- left (BorderSide | None, default:
None) - The left side. Defaults to no border. - top (BorderSide | None, default:
None) - The top side. Defaults to no border. - right (BorderSide | None, default:
None) - The right side. Defaults to no border. - bottom (BorderSide | None, default:
None) - The bottom side. Defaults to no border.
Returns:
- A (Border) - class:
~flet.Borderbuilt from the provided sides.
symmetricclassmethod
symmetric(
vertical: BorderSide | None = None,
horizontal: BorderSide | None = None,
) -> BorderCreates a border with symmetrical vertical and horizontal sides.
The vertical argument applies to the left and right sides,
and the horizontal argument applies to the top and bottom
sides.
Parameters:
- vertical (BorderSide | None, default:
None) - The side applied to the left and right. - horizontal (BorderSide | None, default:
None) - The side applied to the top and bottom.
Returns:
- A (Border) - class:
~flet.Borderwith mirrored side pairs.
Examples
Example 1
import flet as ft
def main(page: ft.Page):
page.title = "Containers with different borders"
page.add(
ft.SafeArea(
content=ft.Column(
controls=[
ft.Row(
controls=[
ft.Container(
bgcolor=ft.Colors.AMBER,
padding=15,
border=ft.Border.all(10, ft.Colors.PINK_600),
border_radius=ft.BorderRadius.all(30),
width=150,
height=150,
),
ft.Container(
bgcolor=ft.Colors.DEEP_PURPLE,
padding=15,
border=ft.Border.all(3, ft.Colors.LIGHT_GREEN_ACCENT),
border_radius=ft.BorderRadius.only(
top_left=10, bottom_right=10
),
width=150,
height=150,
),
ft.Container(
bgcolor=ft.Colors.BLUE_GREY_900,
padding=15,
border=ft.Border.symmetric(
vertical=ft.BorderSide(8, ft.Colors.YELLOW_800)
),
width=150,
height=150,
),
]
)
]
)
)
)
if __name__ == "__main__":
ft.run(main)