Skip to content

ScrollMode 继承自: Enum

定义可滚动控件的滚动行为与滚动条的可见性。

例如,将其赋值给 scroll 时,每个取值都会在内部映射到特定的 Scrollbar 配置。

示例 ​

python
import flet as ft


def showcase_card(scroll_mode: ft.ScrollMode) -> ft.Container:
    return ft.Container(
        width=280,
        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(scroll_mode.name, weight=ft.FontWeight.BOLD),
                ft.Text("Scroll inside this panel", size=12),
                ft.Container(
                    height=170,
                    border=ft.Border.all(1, ft.Colors.OUTLINE),
                    border_radius=8,
                    bgcolor=ft.Colors.SURFACE,
                    padding=8,
                    content=ft.Column(
                        spacing=4,
                        scroll=scroll_mode,
                        controls=[ft.Text(f"Item {i + 1}") for i in range(24)],
                    ),
                ),
            ],
        ),
    )


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

    page.appbar = ft.AppBar(title="ScrollMode Showcase")
    page.add(
        ft.SafeArea(
            content=ft.Column(
                controls=[
                    ft.Text(
                        "Compare scrollbar visibility and scrolling behavior modes."
                    ),
                    ft.Row(
                        wrap=True,
                        spacing=12,
                        expand=True,
                        scroll=ft.ScrollMode.AUTO,
                        alignment=ft.MainAxisAlignment.CENTER,
                        controls=[
                            showcase_card(scroll_mode) for scroll_mode in ft.ScrollMode
                        ],
                    ),
                ],
            ),
        )
    )


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

枚举值 ​

名称类型默认值说明
AUTO—'auto'Scrolling is enabled and scroll bar is only shown when scrolling occurs. Scrollbar equivalent: python ft.Scrollbar( thickness=4.0 if page.platform.is_mobile() and not page.web else None, )
ADAPTIVE—'adaptive'Scrolling is enabled and scroll bar is always shown when running app as web or desktop. Scrollbar equivalent: python ft.Scrollbar( thumb_visibility=page.web or not page.platform.is_mobile(), thickness=4.0 if page.platform.is_mobile() and not page.web else None, )
ALWAYS—'always'Scrolling is enabled and scroll bar is always shown. Scrollbar equivalent: python ft.Scrollbar( thumb_visibility=True, thickness=4.0 if page.platform.is_mobile() and not page.web else None, )
HIDDEN—'hidden'Scrolling is enabled, but scroll bar is always hidden. Scrollbar equivalent: python ft.Scrollbar( thickness=0, )

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