Skip to content

RadialGradient 继承自: Gradient

Creates a radial gradient centered at center that ends at radius distance from the center.

More information here.

属性 ​

名称类型默认值说明
centerAlignmentAlignment.CENTER()The center of the gradient, as an offset into the (-1.0, -1.0) x (1.0, 1.0) square describing the gradient which will be mapped onto the paint box. For example, an alignment of (0.0, 0.0) will place the radial gradient in the center of the box.
radiusNumber0.5The radius of the gradient, as a fraction of the shortest side of the paint box. For example, if a radial gradient is painted on a box that is 100.0 pixels wide and 200.0 pixels tall, then a radius of 1.0 will place the 1.0 stop at 100.0 pixels from the center.
focalOptional[Alignment]NoneThe focal point of the gradient. If specified, the gradient will appear to be focused along the vector from center to focal.
focal_radiusNumber0.0The radius of the focal point of gradient, as a fraction of the shortest side of the paint box. For example, if a radial gradient is painted on a box that is 100.0 pixels wide and 200.0 pixels tall, then a radius of 1.0 will place the 1.0 stop at 100.0 pixels from the focal point.
colorslist[ColorValue]requiredThe 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_modeGradientTileModeGradientTileMode.CLAMPHow this gradient should tile the plane beyond in the region before begin and after end.
rotationOptional[Number]NoneThe rotation of the gradient in radians, around the center-point of its bounding box.
stopsOptional[list[Number]]NoneA 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 radial gradient ​

python
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.RadialGradient(
                            center=ft.Alignment(0.7, -0.6),
                            radius=0.2,
                            colors=["0xFFFFFF00", "0xFF0099FF"],
                            stops=[0.4, 1.0],
                        ),
                    )
                ],
            ),
        )
    )


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

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