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 →


pz.column([ ui.rating(4, on_rate), ui.rating(3, on_rate, icon="heart", tint="error"), ui.rating(4.4),], spacing=12)When to use
Section titled “When to use”- To rate an item, a song or an answer.
- To show an average score next to a product or a review.
import pyzed as pzfrom 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))Variants
Section titled “Variants”Options
Section titled “Options”

max=5Code
ui.rating(3, on_rate)

max=10, size=14Code
ui.rating(7, on_rate, max=10, size=14)

icon="heart"Code
ui.rating(4, on_rate, icon="heart", tint="error")

icon="thumbs-up"Code
ui.rating(2, on_rate, icon="thumbs-up", tint="accent", max=3)States and events
Section titled “States and events”

Code
ui.rating(4.4)

disabled=TrueCode
ui.rating(3, on_rate, disabled=True)Events
Section titled “Events”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().
Handling the events
Section titled “Handling the events”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)from dataclasses import dataclass
@dataclassclass Rate: stars: int
class Review(pz.App): stars = 3
def update(self, message): match message: case Rate(stars): self.stars = stars
def view(self): return ui.rating(self.stars, Rate) # the class builds the message from the starsfrom dataclasses import dataclass
@dataclass(frozen=True)class State: stars: int = 3
def view(state, set_state): return ui.rating(state.stars, lambda stars: set_state(stars=stars))Properties and API
Section titled “Properties and API”ui.rating
Section titled “ui.rating”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).