DateInput

A widget to select a calendar date.

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

Reference

class toga.DateInput(id=None, style=None, value=None, min=None, max=None, on_change=None)

Bases: Widget

Create a new DateInput widget.

Parameters:
  • id (str | None) – The ID for the widget.

  • style (StyleT | None) – A style object. If no style is provided, a default style will be applied to the widget.

  • value (datetime.date | None) – The initial date to display. If not specified, the current date will be used.

  • min (datetime.date | None) – The earliest date (inclusive) that can be selected.

  • max (datetime.date | None) – The latest date (inclusive) that can be selected.

  • on_change (toga.widgets.dateinput.OnChangeHandler | None) – A handler that will be invoked when the value changes.

property 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:

ValueError – If set to a date outside of the supported range.

property 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:

ValueError – If set to a date outside of the supported range.

property on_change: OnChangeHandler

The handler to invoke when the date value changes.

property 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 of the min/max range, it will be clipped.

protocol toga.widgets.dateinput.OnChangeHandler

typing.Protocol.

Classes that implement this protocol must have the following methods / attributes:

__call__(widget, /, **kwargs)

A handler that will be invoked when a change occurs.

Parameters:
  • widget (DateInput) – The DateInput that was changed.

  • kwargs (Any) – Ensures compatibility with arguments added in future versions.

Return type:

object