Skip to content

PaintLinearGradient 继承自: PaintGradient

More information on Linear gradient here.

属性 ​

名称类型默认值说明
beginOptional[OffsetValue]requiredThe offset at which stop 0.0 of the gradient is placed.
endOptional[OffsetValue]requiredThe offset at which stop 1.0 of the gradient is placed.
colorslist[ColorValue]requiredThe colors the gradient should obtain at each of the stops. This list must contain at least two colors. Note: If color_stops is not None, this list must have the same length as color_stops.
color_stopsOptional[list[Number]]NoneA list of values from 0.0 to 1.0 that denote fractions along the gradient. Note: If non-none, this list must have the same length as colors. If the first value is not 0.0, then a stop with position 0.0 and a color equal to the first color in colors is implied. If the last value is not 1.0, then a stop with position 1.0 and a color equal to the last color in colors is implied.
tile_modeGradientTileModeGradientTileMode.CLAMPHow this gradient should tile the plane beyond in the region before begin and after end.

方法 ​

名称类型默认值说明
copy'PaintLinearGradient'—返回此对象的副本,可覆盖指定属性。

示例 ​

Canvas paint ​

python
import flet as ft
import flet.canvas as cv


def main(page: ft.Page):
    page.add(
        ft.SafeArea(
            content=ft.Column(
                controls=[
                    cv.Canvas(
                        width=float("inf"),
                        expand=True,
                        shapes=[
                            cv.Rect(
                                x=10,
                                y=10,
                                width=100,
                                height=100,
                                border_radius=5,
                                paint=ft.Paint(
                                    style=ft.PaintingStyle.FILL,
                                    gradient=ft.PaintLinearGradient(
                                        begin=(0, 10),
                                        end=(100, 50),
                                        colors=[ft.Colors.BLUE, ft.Colors.YELLOW],
                                    ),
                                ),
                            ),
                        ],
                    )
                ],
            ),
        )
    )


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

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