Skip to content

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 →

Time pickerTime picker
  • 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 pz
from 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)))
Time picker: "HH:mm"Time picker: "HH:mm"
"HH:mm"
Code
ui.TimePicker(value="14:30", on_change=on_change)
Time picker: "h:mm A"Time picker: "h:mm A"
"h:mm A"
Code
ui.TimePicker(value="14:30", format="h:mm A", on_change=on_change)
Time picker: "HH:mm:ss"Time picker: "HH:mm:ss"
"HH:mm:ss"
Code
ui.TimePicker(value="14:30:15", format="HH:mm:ss", on_change=on_change)
Time picker: format="HH:mm:ss"Time picker: format="HH:mm:ss"
format="HH:mm:ss"
Code
ui.TimePicker(value="06:15:30", format="HH:mm:ss", on_change=on_change)
Time picker: format="h:mm A"Time picker: format="h:mm A"
format="h:mm A"
Code
ui.TimePicker(value="14:30", format="h:mm A", minute_step=15, on_change=on_change)

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().

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)
class TimePicker

A 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).

Full reference →

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.

Full reference →

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.

Full reference →