Skip to content

TileAffinity 继承自: Enum

Where to place a control in controls that use ListTile to position a control next to a label.

示例 ​

python
import flet as ft


def showcase_card(affinity: ft.TileAffinity) -> ft.Container:
    tile = ft.ExpansionTile(
        title="Project settings",
        subtitle="Compare where the expand arrow appears.",
        affinity=affinity,
        expanded=True,
        controls=[
            ft.ListTile(title="General"),
            ft.ListTile(title="Notifications"),
        ],
    )

    return ft.Container(
        width=360,
        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(affinity.name, weight=ft.FontWeight.BOLD),
                tile,
            ],
        ),
    )


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

    page.appbar = ft.AppBar(title="TileAffinity Showcase")
    page.add(
        ft.SafeArea(
            content=ft.Column(
                controls=[
                    ft.Text("Compare expand-arrow placement in ExpansionTile."),
                    ft.Row(
                        wrap=True,
                        spacing=12,
                        expand=True,
                        scroll=ft.ScrollMode.AUTO,
                        alignment=ft.MainAxisAlignment.CENTER,
                        controls=[
                            showcase_card(affinity) for affinity in ft.TileAffinity
                        ],
                    ),
                ],
            ),
        )
    )


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

枚举值 ​

名称类型默认值说明
LEADING—'leading'Positions the control on the leading edge, and the secondary control, if any, on the trailing edge.
TRAILING—'trailing'Positions the control on the trailing edge, and the secondary control, if any, on the leading edge.
PLATFORM—'platform'Positions the control relative to the text in the fashion that is typical for the current platform, and place the secondary control on the opposite side.

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