PaintLinearGradient
More information on Linear gradient here.
Inherits: PaintGradient
Properties
begin- The offset at which stop0.0of the gradient is placed.color_stops- A list of values from0.0to1.0that denote fractions along the gradient.colors- The colors the gradient should obtain at each of the stops.end- The offset at which stop1.0of the gradient is placed.tile_mode- How this gradient should tile the plane beyond in the region before begin and after end.
Methods
copy- Returns a copy of this object with the specified properties overridden.
Properties
begininstance-attribute
begin: Optional[OffsetValue]The offset at which stop 0.0 of the gradient is placed.
color_stopsclass-attributeinstance-attribute
color_stops: Optional[list[Number]] = NoneA list of values from 0.0 to 1.0 that denote fractions along the gradient.
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.
colorsinstance-attribute
colors: list[ColorValue]The colors the gradient should obtain at each of the stops. This list must contain at least two colors.
If color_stops is not None,
this list must have the same length as color_stops.
endinstance-attribute
end: Optional[OffsetValue]The offset at which stop 1.0 of the gradient is placed.
tile_modeclass-attributeinstance-attribute
tile_mode: GradientTileMode = GradientTileMode.CLAMPHow this gradient should tile the plane beyond in the region before begin and after end.
Methods
copy
copy(begin: Optional[OffsetValue] = None, end: Optional[OffsetValue] = None, colors: Optional[list[str]] = None, color_stops: Optional[list[Number]] = None, tile_mode: Optional[GradientTileMode] = None)Returns a copy of this object with the specified properties overridden.
Examples
Canvas paint
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)
