Skip to content

Rating

A row of stars (or any icon) where the first value are lit. Clicking a star sends its number to on_change; with clearable a click on the lit one sends 0. Without on_change it only shows the score, rounded to the nearest star.

ui.rating · Category: Forms · Full reference →

RatingRating
  • To rate an item, a song or an answer.
  • To show an average score next to a product or a review.
import pyzed as pz
from pyzed import ui
class Review(pz.App):
def __init__(self):
self.stars = 3
def view(self):
return ui.rating(self.stars, lambda stars: setattr(self, "stars", stars))
Rating: max=5Rating: max=5
max=5
Code
ui.rating(3, on_rate)
Rating: max=10, size=14Rating: max=10, size=14
max=10, size=14
Code
ui.rating(7, on_rate, max=10, size=14)
Rating: icon="heart"Rating: icon="heart"
icon="heart"
Code
ui.rating(4, on_rate, icon="heart", tint="error")
Rating: icon="thumbs-up"Rating: icon="thumbs-up"
icon="thumbs-up"
Code
ui.rating(2, on_rate, icon="thumbs-up", tint="accent", max=3)
Rating: Read onlyRating: Read only
Read only
Code
ui.rating(4.4)
Rating: disabled=TrueRating: disabled=True
disabled=True
Code
ui.rating(3, on_rate, disabled=True)

Rating has 1 event of its own, listed below. Like every widget it also has the 18 common events (click, double_click, right_click, mouse_enter, drag, key_down, resize…), attached with .on(...): see Events and Events of every component.

Event Handler gets When
on_change (stars) Callable that receives the number of stars picked (0 to max).

Handler gets is what Pyzed passes to your callable: () means nothing. Any handler can also be a message (a value that is not callable), which goes to update().

The same events written three ways. Imperative: methods of the app change self. Declarative: the handlers produce messages and one update() decides. Functional: a pure function draws an immutable state and asks for changes with set_state(...). See Imperative, declarative and functional.

class Review(pz.App):
def __init__(self):
self.stars = 3
def rate(self, stars): # on_change: the number of stars (0 when cleared)
self.stars = stars
def view(self):
return pz.column([ui.rating(self.stars, self.rate), ui.label(f"{self.stars} of 5")], spacing=8)
rating(
value,
on_change=None,
*,
max=5,
icon='star',
size=18,
tint='warning',
clearable=True,
disabled=False,
theme=None,
)

A row of stars (or any icon) to give or show a score. Clicking a star sends its number; with clearable a click on the lit one sends 0. Without on_change it only shows the value, rounded to the nearest star. Focused, the arrows change it by one.

Property Default Description
value required How many stars are lit (rounded).
max 5 How many stars there are.
icon "star" Lucide icon drawn for each star.
size 18 Icon size in pixels.
tint "warning" Color of the lit stars (a theme token or hex color).
clearable True A click on the current value sends 0.
disabled False Disables it (ignores clicks).
theme None Theme to use instead of the current one (pyzed.theme.current()).

Events: on_change (events).

Full reference →