Skip to content

PointMode 继承自: Enum

Defines how a list of points is interpreted when drawing a set of points.

示例 ​

python
import flet as ft
import flet.canvas as cv

POINTS = [
    (25, 75),
    (70, 30),
    (115, 75),
    (160, 30),
    (205, 75),
]


def showcase_card(mode: cv.PointMode) -> 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),
                cv.Canvas(
                    width=240,
                    height=110,
                    shapes=[
                        cv.Points(
                            points=POINTS,
                            point_mode=mode,
                            paint=ft.Paint(
                                color=ft.Colors.PRIMARY,
                                stroke_width=12,
                                stroke_cap=ft.StrokeCap.ROUND,
                            ),
                        )
                    ],
                ),
            ],
        ),
    )


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

    page.appbar = ft.AppBar(title="PointMode Showcase")
    page.add(
        ft.SafeArea(
            content=ft.Column(
                controls=[
                    ft.Text(
                        "Compare how the same coordinate list is interpreted "
                        "by each point mode."
                    ),
                    ft.Row(
                        wrap=True,
                        spacing=12,
                        expand=True,
                        scroll=ft.ScrollMode.AUTO,
                        alignment=ft.MainAxisAlignment.CENTER,
                        controls=[showcase_card(mode) for mode in cv.PointMode],
                    ),
                ],
            ),
        )
    )


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

枚举值 ​

名称类型默认值说明
POINTS—'points'Draw each point separately. If the Paint.stroke_cap is StrokeCap.ROUND, then each point is drawn as a circle with the diameter of the Paint.stroke_width, filled as described by the Paint (ignoring Paint.style). Otherwise, each point is drawn as an axis-aligned square with sides of length Paint.stroke_width, filled as described by the Paint (ignoring Paint.style).
LINES—'lines'Draw each sequence of two points as a line segment. If the number of points is odd, then the last point is ignored. The lines are stroked as described by the Paint (ignoring Paint.style).
POLYGON—'polygon'Draw the entire sequence of point as one line. The lines are stroked as described by the Paint (ignoring Paint.style).

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