主题
PaintLinearGradient 继承自: PaintGradient
More information on Linear gradient here.
属性
| 名称 | 类型 | 默认值 | 说明 |
|---|---|---|---|
begin | Optional[OffsetValue] | required | The offset at which stop 0.0 of the gradient is placed. |
end | Optional[OffsetValue] | required | The offset at which stop 1.0 of the gradient is placed. |
colors | list[ColorValue] | required | The 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_stops | Optional[list[Number]] | None | A 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_mode | GradientTileMode | GradientTileMode.CLAMP | How 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)