Time picker
ui.TimePicker is a field for a time of day. Its popup has a column of hours, one of minutes (every minute_step minutes), seconds when the format has ss and AM/PM when it has A or h. ↑ and ↓ move it by one step from the keyboard. on_change receives a datetime.time.
ui.TimePicker · Category: Dates and times · Full reference →


pz.row([ pz.container(ui.TimePicker(value="14:30", on_change=on_change), width=140, height=290, align_y="start"), pz.container(ui.TimePicker(value="14:30", format="h:mm A", minute_step=15, on_change=on_change), width=140, height=290, align_y="start"),], spacing=24)When to use
Section titled “When to use”- For alarms, opening hours, meetings and reminders.
format="HH:mm"is 24 hours;"h:mm A"is 12 hours with AM/PM;"HH:mm:ss"adds seconds.
import pyzed as pzfrom pyzed import ui
import datetime
class Alarm(pz.App): def __init__(self): self.at = datetime.time(7, 30)
def view(self): return ui.field("Wake me at", ui.TimePicker(value=self.at, format="h:mm A", on_change=lambda e: setattr(self, "at", e.value)))Variants
Section titled “Variants”Format
Section titled “Format”

"HH:mm"Code
ui.TimePicker(value="14:30", on_change=on_change)

"h:mm A"Code
ui.TimePicker(value="14:30", format="h:mm A", on_change=on_change)

"HH:mm:ss"Code
ui.TimePicker(value="14:30:15", format="HH:mm:ss", on_change=on_change)

format="HH:mm:ss"Code
ui.TimePicker(value="06:15:30", format="HH:mm:ss", on_change=on_change)

format="h:mm A"Code
ui.TimePicker(value="14:30", format="h:mm A", minute_step=15, on_change=on_change)Events
Section titled “Events”Time picker has 3 events 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.
It is a pz.Component, so it also raises on_mount and on_unmount, and its handlers get a pz.Event whose value holds the data.
| Event | Handler gets | When |
|---|---|---|
on_change |
(event) |
Receives event.value: a datetime.time or None. |
on_open |
(event) |
The list opened. |
on_close |
(event) |
The list closed. |
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.
import datetime
class Alarm(pz.App): def __init__(self): self.at = datetime.time(7, 30)
def changed(self, event): # on_change: event.value is a datetime.time self.at = event.value
def view(self): return pz.column([ ui.TimePicker(value=self.at, format="h:mm A", on_change=self.changed), ui.label(f"Alarm at {ui.format_time(self.at, 'HH:mm')}"), ], spacing=8, width=200)import datetimefrom dataclasses import dataclass
@dataclassclass At: time: datetime.time
class Alarm(pz.App): at = datetime.time(7, 30)
def update(self, message): match message: case At(time): self.at = time
def view(self): return ui.TimePicker(value=self.at, on_change=lambda e: At(e.value))import datetimefrom dataclasses import dataclass
@dataclass(frozen=True)class State: at: datetime.time = datetime.time(7, 30)
def view(state, set_state): return ui.TimePicker(value=state.at, minute_step=15, on_change=lambda e: set_state(at=e.value))Properties and API
Section titled “Properties and API”ui.TimePicker
Section titled “ui.TimePicker”class TimePickerA component: a time field with columns of hours and minutes (and seconds, and AM/PM with a 12-hour format) in a popup. Once clicked, ↑/↓ change it by minute_step. See the Time picker page.
| Property | Default | Description |
|---|---|---|
value |
None |
The time (datetime.time, "14:30" or None). |
format |
"HH:mm" |
"HH:mm", "HH:mm:ss", "h:mm A"… |
placeholder |
"" |
Hint while empty. |
minute_step |
5 |
Minutes between the ones offered. |
min |
None |
The earliest time. |
max |
None |
The latest time. |
clearable |
True |
Shows an x that empties it. |
disabled |
False |
Greys it out. |
invalid |
False |
Paints the border in the error color. |
Events: on_change, on_open, on_close (events).
ui.format_time
Section titled “ui.format_time”format_time(value, fmt='HH:mm')Writes a time (or "14:30") with a pattern such as "h:mm A".
| Property | Default | Description |
|---|---|---|
value |
required | A datetime.time or text. |
fmt |
"HH:mm" |
The pattern. |
ui.parse_time
Section titled “ui.parse_time”parse_time(text, fmt='HH:mm')Reads a time: "14:30", "2:30 PM", "14:30:05", with fmt first. None when it is not one.
| Property | Default | Description |
|---|---|---|
text |
required | The text. |
fmt |
"HH:mm" |
The pattern. |