Skip to main content

RatingBar

A Fluent rating bar: a row of stars to show or pick a rating.

Example:

fluent.RatingBar(value=3)
fluent.RatingBar(value=4.5, read_only=True)
RatingBar
RatingBar

Inherits: LayoutControl

Properties

  • autofocus - Whether this rating bar should be focused on initial display.
  • color - The color of rated stars.
  • icon_size - The size of each star.
  • max - The number of stars.
  • read_only - Whether the rating is only shown and can't be changed.
  • spacing - The space between stars.
  • unrated_color - The color of unrated stars.
  • value - The rating, from 0 to max.

Events

  • on_change - Called when the user changes the rating.

Example​

Fluent RatingBar​

Sourceplay_arrowTry Online
import flet_fluent_ui as fluent

import flet as ft


def main(page: ft.Page):
page.title = "Fluent RatingBar"

def handle_change(e: ft.Event[fluent.RatingBar]):
status.value = f"You rated it {e.control.value:g} stars"

status = ft.Text("Rate this app")

page.add(
ft.SafeArea(
content=ft.Column(
controls=[
ft.Row(
controls=[
ft.Text("Average"),
fluent.RatingBar(value=4.3, read_only=True, icon_size=16),
ft.Text("4.3"),
],
),
fluent.RatingBar(key="rating", on_change=handle_change),
status,
],
)
)
)


if __name__ == "__main__":
ft.run(main)
rating_bar
Rating with three stars

Properties​

autofocusclass-attributeinstance-attribute​

autofocus: bool = False

Whether this rating bar should be focused on initial display.

colorclass-attributeinstance-attribute​

color: ColorValue | None = None

The color of rated stars.

If None, the accent color of the theme is used.

icon_sizeclass-attributeinstance-attribute​

icon_size: Number = 20

The size of each star.

maxclass-attributeinstance-attribute​

max: int = 5

The number of stars.

read_onlyclass-attributeinstance-attribute​

read_only: bool = False

Whether the rating is only shown and can't be changed.

spacingclass-attributeinstance-attribute​

spacing: Number = 8

The space between stars.

unrated_colorclass-attributeinstance-attribute​

unrated_color: ColorValue | None = None

The color of unrated stars.

valueclass-attributeinstance-attribute​

value: Number = 0

The rating, from 0 to max. Fractional ratings fill stars partially.

Events​

on_changeclass-attributeinstance-attribute​

on_change: ControlEventHandler[RatingBar] | None = None

Called when the user changes the rating.

The data property of the event handler argument contains the new rating.