Text, images and progress¶
Use words and a picture to explain a number in your Python script’s native interface. A reading goal is easier to follow when the bar has a book title and a chapter count beside it.
"""A bookmark that tracks chapters as you finish them."""
from dataclasses import dataclass
from juno import ui
CHAPTERS = 8
@dataclass
class State:
read: int = 3
state = State()
def finish_chapter():
state.read = min(state.read + 1, CHAPTERS)
def body(s):
return ui.VStack(
ui.HStack(ui.Image(symbol="book.fill", color="indigo", size=24),
ui.Text("The Glass Orchard", font="title2", weight="bold")),
ui.Text(f"{s.read} of {CHAPTERS} chapters read"),
ui.ProgressView(value=s.read / CHAPTERS, accessibility_label="Reading progress"),
ui.Button("Finish a chapter", on_press=finish_chapter,
style="bordered", disabled=s.read == CHAPTERS),
spacing=12, alignment="leading", padding=20, width="fill", max_width=480)
if __name__ == "__main__":
ui.run(body, state, title="Reading goal")
Give the number a name¶
Use Text for the title and chapter count, and Image(symbol="book.fill") for the book symbol. For your own picture, give Image a file path or encoded image bytes. Give a picture that carries information an accessibility_label describing what it shows.
Show how far along you are¶
A ProgressView with a value from zero to one draws a bar. Divide chapters read by chapters in the book to get that fraction. Tap Finish a chapter to move from three chapters read to four. When you don’t know the fraction, omit value to show a spinner.
For a longer job with a Cancel button, see work in small steps.
Parameters¶
Parameter |
Default |
Meaning |
|---|---|---|
|
Required |
A string; use |
|
|
Text style: |
|
|
None for the style’s own, or |
|
|
None, |
|
|
None, or 6 to 160 points at the default text size. |
|
|
None for the label colour, a colour name, or hex. |
|
|
When True, render inline Markdown in |
Common keywords |
|
Parameter |
Default |
Meaning |
|---|---|---|
|
|
Existing image path relative to the script’s working directory, or PNG/JPEG/HEIC/HEIF/GIF bytes (first frame), at most 700 KB. |
|
|
SF Symbol name such as |
|
|
|
|
|
Symbol only: None for the label colour, a colour name, or hex. |
|
|
Symbol only: True draws the symbol’s own colours. |
|
|
Symbol only: None for body, or a Text style that sizes the symbol. |
|
|
Symbol only: True draws color in layered opacities. |
|
|
Symbol only: two or three colours for the symbol’s layers. |
|
|
Symbol only: None, or 6 to 160 points at the default text size. |
Common keywords |
|
Parameter |
Default |
Meaning |
|---|---|---|
|
|
None for activity, or a finite number from 0 to 1; not bool. |
|
|
Optional caption string. |
Common keywords |
|
Seen in¶
Run Device Dashboard from Home’s Native UI section and look at the memory card for another use of a progress bar.