DatePicker#

Includes date picker.

https://github.com/HeaTTheatR/KivyMD-data/raw/master/gallery/kivymddoc/picker-previous.png

Warning

The widget is under testing. Therefore, we would be grateful if you would let us know about the bugs found.

Usage

from kivy.lang import Builder

from kivymd.app import MDApp
from kivymd.uix.pickers import MDDatePicker

KV = '''
MDFloatLayout:

    MDTopAppBar:
        title: "MDDatePicker"
        pos_hint: {"top": 1}
        elevation: 10

    MDRaisedButton:
        text: "Open date picker"
        pos_hint: {'center_x': .5, 'center_y': .5}
        on_release: app.show_date_picker()
'''


class Test(MDApp):
    def build(self):
        return Builder.load_string(KV)

    def on_save(self, instance, value, date_range):
        '''
        Events called when the "OK" dialog box button is clicked.

        :type instance: <kivymd.uix.picker.MDDatePicker object>;

        :param value: selected date;
        :type value: <class 'datetime.date'>;

        :param date_range: list of 'datetime.date' objects in the selected range;
        :type date_range: <class 'list'>;
        '''

        print(instance, value, date_range)

    def on_cancel(self, instance, value):
        '''Events called when the "CANCEL" dialog box button is clicked.'''

    def show_date_picker(self):
        date_dialog = MDDatePicker()
        date_dialog.bind(on_save=self.on_save, on_cancel=self.on_cancel)
        date_dialog.open()


Test().run()
https://github.com/HeaTTheatR/KivyMD-data/raw/master/gallery/kivymddoc/MDDatePicker.gif

Open date dialog with the specified date#

def show_date_picker(self):
    date_dialog = MDDatePicker(year=1983, month=4, day=12)
    date_dialog.open()
https://github.com/HeaTTheatR/KivyMD-data/raw/master/gallery/kivymddoc/previous-date.png

Interval date#

You can set the time interval from and to the set date. All days of the week that are not included in this range will have the status disabled.

def show_date_picker(self):
    date_dialog = MDDatePicker(
        min_date=datetime.date(2021, 2, 15),
        max_date=datetime.date(2021, 3, 27),
    )
    date_dialog.open()
https://github.com/HeaTTheatR/KivyMD-data/raw/master/gallery/kivymddoc/range-date.gif

The range of available dates can be changed in the picker dialog:

https://github.com/HeaTTheatR/KivyMD-data/raw/master/gallery/kivymddoc/change-range-date.gif

Select year#

https://github.com/HeaTTheatR/KivyMD-data/raw/master/gallery/kivymddoc/select-year-date.gif

Warning

The list of years when opening is not automatically set to the current year.

You can set the range of years using the min_year and max_year attributes:

def show_date_picker(self):
    date_dialog = MDDatePicker(min_year=2021, max_year=2030)
    date_dialog.open()
https://github.com/HeaTTheatR/KivyMD-data/raw/master/gallery/kivymddoc/min-max-year-date.png

Set and select a date range#

def show_date_picker(self):
    date_dialog = MDDatePicker(mode="range")
    date_dialog.open()
https://github.com/HeaTTheatR/KivyMD-data/raw/master/gallery/kivymddoc/set-select-range-date.gif

API - kivymd.uix.pickers.datepicker.datepicker#

class kivymd.uix.pickers.datepicker.datepicker.BaseDialogPicker(**kwargs)#

Base class for MDDatePicker and MDTimePicker classes.

Events:
on_save

Events called when the “OK” dialog box button is clicked.

on_cancel

Events called when the “CANCEL” dialog box button is clicked.

title_input#

Dialog title fot input date.

MDDatePicker(title_input="INPUT DATE")
https://github.com/HeaTTheatR/KivyMD-data/raw/master/gallery/kivymddoc/md-date-picker-input-date.png

title_input is an StringProperty and defaults to INPUT DATE.

title#

Dialog title fot select date.

MDDatePicker(title="SELECT DATE")
https://github.com/HeaTTheatR/KivyMD-data/raw/master/gallery/kivymddoc/md-date-picker-select-date.png

title is an StringProperty and defaults to SELECT DATE.

radius#

Radius list for the four corners of the dialog.

MDDatePicker(radius=[7, 7, 7, 26])
https://github.com/HeaTTheatR/KivyMD-data/raw/master/gallery/kivymddoc/md-date-picker-radius.png

radius is an ListProperty and defaults to [7, 7, 7, 7].

primary_color#

Background color of toolbar in (r, g, b, a) format.

MDDatePicker(primary_color=get_color_from_hex("#72225b"))
https://github.com/HeaTTheatR/KivyMD-data/raw/master/gallery/kivymddoc/primary-color-date.png

primary_color is an ColorProperty and defaults to None.

accent_color#

Background color of calendar/clock face in (r, g, b, a) format.

MDDatePicker(
    primary_color=get_color_from_hex("#72225b"),
    accent_color=get_color_from_hex("#5d1a4a"),
)
https://github.com/HeaTTheatR/KivyMD-data/raw/master/gallery/kivymddoc/accent-color-date.png

accent_color is an ColorProperty and defaults to None.

selector_color#

Background color of the selected day of the month or hour in (r, g, b, a) format.

MDDatePicker(
    primary_color=get_color_from_hex("#72225b"),
    accent_color=get_color_from_hex("#5d1a4a"),
    selector_color=get_color_from_hex("#e93f39"),
)
https://github.com/HeaTTheatR/KivyMD-data/raw/master/gallery/kivymddoc/selector-color-date.png

selector_color is an ColorProperty and defaults to None.

text_toolbar_color#

Color of labels for text on a toolbar in (r, g, b, a) format.

MDDatePicker(
    primary_color=get_color_from_hex("#72225b"),
    accent_color=get_color_from_hex("#5d1a4a"),
    selector_color=get_color_from_hex("#e93f39"),
    text_toolbar_color=get_color_from_hex("#cccccc"),
)
https://github.com/HeaTTheatR/KivyMD-data/raw/master/gallery/kivymddoc/text-toolbar-color-date.png

text_toolbar_color is an ColorProperty and defaults to None.

text_color#

Color of text labels in calendar/clock face in (r, g, b, a) format.

MDDatePicker(
    primary_color=get_color_from_hex("#72225b"),
    accent_color=get_color_from_hex("#5d1a4a"),
    selector_color=get_color_from_hex("#e93f39"),
    text_toolbar_color=get_color_from_hex("#cccccc"),
    text_color=("#ffffff"),
)
https://github.com/HeaTTheatR/KivyMD-data/raw/master/gallery/kivymddoc/text-color-date.png

text_color is an ColorProperty and defaults to None.

text_current_color#

Color of the text of the current day of the month/hour in (r, g, b, a) format.

MDDatePicker(
    primary_color=get_color_from_hex("#72225b"),
    accent_color=get_color_from_hex("#5d1a4a"),
    selector_color=get_color_from_hex("#e93f39"),
    text_toolbar_color=get_color_from_hex("#cccccc"),
    text_color=("#ffffff"),
    text_current_color=get_color_from_hex("#e93f39"),
)
https://github.com/HeaTTheatR/KivyMD-data/raw/master/gallery/kivymddoc/text-current-color-date.png

text_current_color is an ColorProperty and defaults to None.

text_button_color#

Text button color in (r, g, b, a) format.

MDDatePicker(
    primary_color=get_color_from_hex("#72225b"),
    accent_color=get_color_from_hex("#5d1a4a"),
    selector_color=get_color_from_hex("#e93f39"),
    text_toolbar_color=get_color_from_hex("#cccccc"),
    text_color=("#ffffff"),
    text_current_color=get_color_from_hex("#e93f39"),
    text_button_color=(1, 1, 1, .5),
)
https://github.com/HeaTTheatR/KivyMD-data/raw/master/gallery/kivymddoc/text-button-color-date.png

text_button_color is an ColorProperty and defaults to None.

input_field_background_color#

Background color of input fields in (r, g, b, a) format.

MDDatePicker(
    primary_color=get_color_from_hex("#72225b"),
    accent_color=get_color_from_hex("#5d1a4a"),
    selector_color=get_color_from_hex("#e93f39"),
    text_toolbar_color=get_color_from_hex("#cccccc"),
    text_color=("#ffffff"),
    text_current_color=get_color_from_hex("#e93f39"),
    input_field_background_color=(1, 1, 1, 0.2),
)
https://github.com/HeaTTheatR/KivyMD-data/raw/master/gallery/kivymddoc/input-field-background-color-date.png

input_field_background_color is an ColorProperty and defaults to None.

input_field_text_color#

Text color of input fields in (r, g, b, a) format.

Background color of input fields.

MDDatePicker(
    primary_color=get_color_from_hex("#72225b"),
    accent_color=get_color_from_hex("#5d1a4a"),
    selector_color=get_color_from_hex("#e93f39"),
    text_toolbar_color=get_color_from_hex("#cccccc"),
    text_color=("#ffffff"),
    text_current_color=get_color_from_hex("#e93f39"),
    input_field_background_color=(1, 1, 1, 0.2),
    input_field_text_color=(1, 1, 1, 1),
)
https://github.com/HeaTTheatR/KivyMD-data/raw/master/gallery/kivymddoc/input-field-background-color-date.png

input_field_text_color is an ColorProperty and defaults to None.

font_name#

Font name for dialog window text.

MDDatePicker(
    primary_color=get_color_from_hex("#72225b"),
    accent_color=get_color_from_hex("#5d1a4a"),
    selector_color=get_color_from_hex("#e93f39"),
    text_toolbar_color=get_color_from_hex("#cccccc"),
    text_color=("#ffffff"),
    text_current_color=get_color_from_hex("#e93f39"),
    input_field_background_color=(1, 1, 1, 0.2),
    input_field_text_color=(1, 1, 1, 1),
    font_name="Weather.ttf",

)
https://github.com/HeaTTheatR/KivyMD-data/raw/master/gallery/kivymddoc/font-name-date.png

font_name is an StringProperty and defaults to ‘Roboto’.

on_save(self, *args)#

Events called when the “OK” dialog box button is clicked.

on_cancel(self, *args)#

Events called when the “CANCEL” dialog box button is clicked.

class kivymd.uix.pickers.datepicker.datepicker.DatePickerInputField(**kwargs)#

Implements date input in dd/mm/yyyy format.

helper_text_mode#
owner#
set_error(self)#

Sets a text field to an error state.

input_filter(self, value: str, boolean: bool)#

Filters the input according to the specified mode.

is_numeric(self, value: str)#

Returns true if the value of the value argument can be converted to an integer, or if the value of the value argument is ‘/’.

get_list_date(self)#

Returns a list as [dd, mm, yyyy] from a text fied for entering a date.

class kivymd.uix.pickers.datepicker.datepicker.MDDatePicker(year=None, month=None, day=None, firstweekday=0, **kwargs)#

Base class for MDDatePicker and MDTimePicker classes.

Events:
on_save

Events called when the “OK” dialog box button is clicked.

on_cancel

Events called when the “CANCEL” dialog box button is clicked.

text_weekday_color#

Text color of weekday names in (r, g, b, a) format.

https://github.com/HeaTTheatR/KivyMD-data/raw/master/gallery/kivymddoc/md-date-picker-text-weekday-color.png

text_weekday_color is an ColorProperty and defaults to None.

helper_text#

Helper text when entering an invalid date.

https://github.com/HeaTTheatR/KivyMD-data/raw/master/gallery/kivymddoc/md-date-picker-helper-text.png

helper_text is an StringProperty and defaults to ‘Wrong date’.

day#

The day of the month to be opened by default. If not specified, the current number will be used.

See Open date dialog with the specified date for more information.

day is an NumericProperty and defaults to 0.

month#

The number of month to be opened by default. If not specified, the current number will be used.

See Open date dialog with the specified date for more information.

month is an NumericProperty and defaults to 0.

year#

The year of month to be opened by default. If not specified, the current number will be used.

See Open date dialog with the specified date for more information.

year is an NumericProperty and defaults to 0.

min_year#

The year of month to be opened by default. If not specified, the current number will be used.

min_year is an NumericProperty and defaults to 1914.

max_year#

The year of month to be opened by default. If not specified, the current number will be used.

max_year is an NumericProperty and defaults to 2121.

mode#
Dialog type:’picker’ type allows you to select one date;

‘range’ type allows to set a range of dates from which the user can select a date.

Available options are: [‘picker’, ‘range’].

mode is an OptionProperty and defaults to picker.

min_date#

The minimum value of the date range for the ‘mode’ parameter. Must be an object <class ‘datetime.date’>.

See Open date dialog with the specified date for more information.

min_date is an ObjectProperty and defaults to None.

max_date#

The minimum value of the date range for the ‘mode’ parameter. Must be an object <class ‘datetime.date’>.

See Open date dialog with the specified date for more information.

max_date is an ObjectProperty and defaults to None.

date_range_text_error#

Error text that will be shown on the screen in the form of a toast if the minimum date range exceeds the maximum.

date_range_text_error is an StringProperty and defaults to ‘Error date range’.

input_field_cls#

A class that will implement date input in the format dd/mm/yyyy. See DatePickerInputField class for more information.

class CustomInputField(MDTextField):
    owner = ObjectProperty()  # required attribute

    # Required method.
    def set_error(self):
        [...]

    # Required method.
    def get_list_date(self):
        [...]

    # Required method.
    def input_filter(self):
        [...]

def show_date_picker(self):
    date_dialog = MDDatePicker(input_field_cls=CustomInputField)

input_field_cls is an ObjectProperty and defaults to DatePickerInputField.

sel_year#
sel_month#
sel_day#
on_device_orientation(self, instance_theme_manager: ThemeManager, orientation_value: str)#

Called when the device’s screen orientation changes.

on_ok_button_pressed(self)#

Called when the ‘OK’ button is pressed to confirm the date entered.

is_date_valaid(self, date: str)#

Checks the valid of the currently entered date.

transformation_from_dialog_select_year(self)#
transformation_to_dialog_select_year(self)#
transformation_to_dialog_input_date(self)#
transformation_from_dialog_input_date(self, interval: Union[int, float])#
compare_date_range(self)#
update_calendar_for_date_range(self)#
update_text_full_date(self, list_date)#

Updates the title of the week, month and number day name in an open date input dialog.

update_calendar(self, year, month)#
get_field(self)#

Creates and returns a text field object used to enter dates.

get_date_range(self)#
set_text_full_date(self, year, month, day, orientation)#

Returns a string of type “Tue, Feb 2” or “Tue, Feb 2” for a date

choose and a string like “Feb 15 - Mar 23” or “Feb 15,

Mar 23” for

a date range.

set_selected_widget(self, widget)#
set_month_day(self, day)#
set_position_to_current_year(self)#
generate_list_widgets_years(self)#
generate_list_widgets_days(self)#
change_month(self, operation: str)#

Called when “chevron-left” and “chevron-right” buttons are pressed. Switches the calendar to the previous/next month.