主题
LinearGradient 继承自: Gradient
Creates a linear gradient from begin to end.
More information on here.
属性
| 名称 | 类型 | 默认值 | 说明 |
|---|---|---|---|
begin | Alignment | Alignment.CENTER_LEFT() | The offset at which stop 0.0 of the gradient is placed. |
end | Alignment | Alignment.CENTER_RIGHT() | 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. If stops is provided, this list must have the same length as it. |
tile_mode | GradientTileMode | GradientTileMode.CLAMP | How this gradient should tile the plane beyond in the region before begin and after end. |
rotation | Optional[Number] | None | The rotation of the gradient in radians, around the center-point of its bounding box. |
stops | Optional[list[Number]] | None | A list of values from 0.0 to 1.0 that denote fractions along the gradient. If provided, 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. |
示例
Container with linear gradient
python
import math
import flet as ft
def main(page: ft.Page):
page.add(
ft.SafeArea(
content=ft.Column(
controls=[
ft.Container(
alignment=ft.Alignment.CENTER,
width=150,
height=150,
border_radius=ft.BorderRadius.all(5),
gradient=ft.LinearGradient(
begin=ft.Alignment.TOP_LEFT,
end=ft.Alignment(0.8, 1),
tile_mode=ft.GradientTileMode.MIRROR,
rotation=math.pi / 3,
colors=[
"0xff1f005c",
"0xff5b0060",
"0xff870160",
"0xffac255e",
"0xffca485c",
"0xffe16b5c",
"0xfff39060",
"0xffffb56b",
],
),
)
],
),
)
)
if __name__ == "__main__":
ft.run(main)