Skip to content

DateInput

A widget to select a calendar date.

DateInput on macOS

DateInput on Linux (GTK)

DateInput on Linux (Qt)

DateInput on Windows

DateInput on iOS

DateInput on Android

DateInput on Web

Not supported

Usage

import toga

current_date = toga.DateInput()

Notes

  • This widget supports years from 1800 to 8999 inclusive.
  • Properties that return datetime.date objects can also accept:
    • datetime.datetime: The date portion will be extracted.
    • str: Will be parsed as an ISO8601 format date string (e.g., "2023-12-25").
  • On iOS, style directives for changing the widget's color and background color will be ignored. Apple advises against customizing the look and feel of date pickers; as a result, they don't expose APIs to change the color of date widgets.

Reference

toga.DateInput

DateInput(
    id: str | None = None,
    style: StyleT | None = None,
    value: date | None = None,
    min: date | None = None,
    max: date | None = None,
    on_change: OnChangeHandler | None = None,
    **kwargs,
)

Bases: Widget

Create a new DateInput widget.

PARAMETER DESCRIPTION
id

The ID for the widget.

TYPE: str | None DEFAULT: None

style

A style object. If no style is provided, a default style will be applied to the widget.

TYPE: StyleT | None DEFAULT: None

value

The initial date to display. If not specified, the current date will be used.

TYPE: date | None DEFAULT: None

min

The earliest date (inclusive) that can be selected.

TYPE: date | None DEFAULT: None

max

The latest date (inclusive) that can be selected.

TYPE: date | None DEFAULT: None

on_change

A handler that will be invoked when the value changes.

TYPE: OnChangeHandler | None DEFAULT: None

kwargs

Initial style properties.

DEFAULT: {}

max property writable

max: date

The maximum allowable date (inclusive). A value of None will be converted into the highest supported date of 8999-12-31.

When setting this property, the current value and min will be clipped against the new maximum value.

RAISES DESCRIPTION
ValueError

If set to a date outside the supported range.

min property writable

min: date

The minimum allowable date (inclusive). A value of None will be converted into the lowest supported date of 1800-01-01.

When setting this property, the current value and max will be clipped against the new minimum value.

RAISES DESCRIPTION
ValueError

If set to a date outside the supported range.

on_change property writable

on_change: OnChangeHandler

The handler to invoke when the date value changes.

value property writable

value: date

The currently selected date. A value of None will be converted into today's date.

If this property is set to a value outside the min/max range, it will be clipped.

toga.widgets.dateinput.OnChangeHandler

Bases: Protocol

__call__

__call__(widget: DateInput, **kwargs: Any) -> None

A handler that will be invoked when a change occurs.

PARAMETER DESCRIPTION
widget

The DateInput that was changed.

TYPE: DateInput

kwargs

Ensures compatibility with arguments added in future versions.

TYPE: Any DEFAULT: {}