Skip to content

FontWeight 继承自: Enum

The thickness of the glyphs used to draw the text.

示例 ​

python
import flet as ft

SAMPLE_TEXT = "Sphinx of black quartz"


def showcase_card(weight: ft.FontWeight) -> ft.Container:
    return ft.Container(
        width=300,
        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(weight.name, size=12, color=ft.Colors.ON_SURFACE_VARIANT),
                ft.Text(SAMPLE_TEXT, weight=weight, size=24),
            ],
        ),
    )


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

    page.appbar = ft.AppBar(title="FontWeight Showcase")
    page.add(
        ft.SafeArea(
            content=ft.Column(
                controls=[
                    ft.Text("Compare text thickness across all FontWeight values."),
                    ft.Row(
                        wrap=True,
                        spacing=12,
                        expand=True,
                        scroll=ft.ScrollMode.AUTO,
                        alignment=ft.MainAxisAlignment.CENTER,
                        controls=[showcase_card(weight) for weight in ft.FontWeight],
                    ),
                ],
            ),
        )
    )


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

枚举值 ​

名称类型默认值说明
NORMAL—'normal'The default font weight, equal to w400.
BOLD—'bold'A commonly used font weight that is heavier than normal, equal to w700.
W_100—'w100'Thin, the least thick.
W_200—'w200'Extra-light.
W_300—'w300'Light.
W_400—'w400'Normal / regular / plain.
W_500—'w500'Medium.
W_600—'w600'Semi-bold.
W_700—'w700'Bold.
W_800—'w800'Extra-bold.
W_900—'w900'Black, the most thick.

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