Skip to content

PaintingStyle 继承自: Enum

style 在绘制几何图形时使用的策略。

决定一个形状是渲染为填充的内部,还是渲染为描边的轮廓。

示例 ​

python
import flet as ft
import flet.canvas as cv


def showcase_card(style: ft.PaintingStyle) -> ft.Container:
    return ft.Container(
        width=250,
        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(style.name, weight=ft.FontWeight.BOLD),
                cv.Canvas(
                    width=240,
                    height=110,
                    shapes=[
                        cv.Circle(
                            x=120,
                            y=55,
                            radius=34,
                            paint=ft.Paint(
                                style=style,
                                stroke_width=10,
                                color=ft.Colors.PRIMARY,
                            ),
                        )
                    ],
                ),
            ],
        ),
    )


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

    page.appbar = ft.AppBar(title="PaintingStyle Showcase")
    page.add(
        ft.SafeArea(
            content=ft.Column(
                controls=[
                    ft.Text("Compare filled vs outlined rendering for the same shape."),
                    ft.Row(
                        wrap=True,
                        spacing=12,
                        expand=True,
                        scroll=ft.ScrollMode.AUTO,
                        alignment=ft.MainAxisAlignment.CENTER,
                        controls=[showcase_card(style) for style in ft.PaintingStyle],
                    ),
                ],
            ),
        )
    )


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

枚举值 ​

名称类型默认值说明
FILL—'fill'Paint the interior of the shape. For example, circles and polygons are rendered as solid filled regions.
STROKE—'stroke'Paint only the shape outline. Stroke thickness and joins/caps are controlled by properties such as stroke_width, stroke_join, and stroke_cap.

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