Skip to content

GradientTileMode 继承自: Enum

Defines what happens at the edge of a gradient. More information about GradientTileMode here.

示例 ​

python
import flet as ft


def showcase_card(mode: ft.GradientTileMode) -> ft.Container:
    return ft.Container(
        width=320,
        padding=12,
        border=ft.Border.all(1, ft.Colors.RED),
        border_radius=10,
        bgcolor=ft.Colors.SURFACE_CONTAINER_LOW,
        content=ft.Column(
            spacing=8,
            controls=[
                ft.Text(mode.name, weight=ft.FontWeight.BOLD),
                ft.Container(
                    width=240,
                    height=120,
                    border=ft.Border.all(1, ft.Colors.OUTLINE),
                    border_radius=8,
                    gradient=ft.RadialGradient(
                        radius=0.22,
                        colors=[ft.Colors.PRIMARY, ft.Colors.AMBER_400],
                        tile_mode=mode,
                    ),
                ),
            ],
        ),
    )


def main(page: ft.Page):
    page.horizontal_alignment = ft.CrossAxisAlignment.CENTER

    page.appbar = ft.AppBar(title="GradientTileMode Showcase")
    page.add(
        ft.SafeArea(
            content=ft.Column(
                controls=[
                    ft.Text(
                        "Compare how gradients behave outside their defined "
                        "paint region."
                    ),
                    ft.Row(
                        wrap=True,
                        spacing=12,
                        expand=True,
                        scroll=ft.ScrollMode.AUTO,
                        alignment=ft.MainAxisAlignment.CENTER,
                        controls=[showcase_card(mode) for mode in ft.GradientTileMode],
                    ),
                ],
            ),
        )
    )


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

枚举值 ​

名称类型默认值说明
CLAMP—'clamp'Samples beyond the edge are clamped to the nearest color in the defined inner area. 详见 此处.
DECAL—'decal'Samples beyond the edge are treated as transparent black. 详见 此处.
MIRROR—'mirror'Samples beyond the edge are mirrored back and forth across the defined area. 详见 此处.
REPEATED—'repeated'Samples beyond the edge are repeated from the far end of the defined area. 详见 此处.

关注我,学习大模型、大数据、Python等热门技术。