Skip to content
Toga
0.5.3.dev143+gabcc6cdb6

DateInput

A widget to select a calendar date.

/reference/images/dateinput-cocoa.png

Not supported

/reference/images/dateinput-winforms.png

/reference/images/dateinput-android.png

/reference/images/dateinput-iOS.png

/reference/images/dateinput-web.png

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=None,
    style=None,
    value=None,
    min=None,
    max=None,
    on_change=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

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

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

The handler to invoke when the date value changes.

value property writable

value

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, **kwargs)

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: {}