DatePicker#
See also Includes date picker. Warning The widget is under testing. Therefore, we would be grateful if
you would let us know about the bugs found. Usage 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. The range of available dates can be changed in the picker dialog: Warning The list of years when opening is not automatically set
to the current year. You can set the range of years using the
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()
Open date dialog with the specified date#
def show_date_picker(self):
date_dialog = MDDatePicker(year=1983, month=4, day=12)
date_dialog.open()
Interval date#
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()
Select year#
min_year and
max_year attributes:def show_date_picker(self):
date_dialog = MDDatePicker(min_year=2021, max_year=2030)
date_dialog.open()
Set and select a date range#
def show_date_picker(self):
date_dialog = MDDatePicker(mode="range")
date_dialog.open()
API - kivymd.uix.pickers.datepicker.datepicker#
- class kivymd.uix.pickers.datepicker.datepicker.BaseDialogPicker(**kwargs)#
Base class for
MDDatePickerandMDTimePickerclasses.- 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")
title_inputis anStringPropertyand defaults to INPUT DATE.
- title#
Dialog title fot select date.
MDDatePicker(title="SELECT DATE")
titleis anStringPropertyand defaults to SELECT DATE.
- radius#
Radius list for the four corners of the dialog.
MDDatePicker(radius=[7, 7, 7, 26])
radiusis anListPropertyand 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"))
primary_coloris anColorPropertyand 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"), )
accent_coloris anColorPropertyand 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"), )
selector_coloris anColorPropertyand 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"), )
text_toolbar_coloris anColorPropertyand 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"), )
text_coloris anColorPropertyand 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"), )
text_current_coloris anColorPropertyand 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), )
text_button_coloris anColorPropertyand 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), )
input_field_background_coloris anColorPropertyand 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), )
input_field_text_coloris anColorPropertyand 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", )
font_nameis anStringPropertyand 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.
- 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
MDDatePickerandMDTimePickerclasses.- 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.
text_weekday_coloris anColorPropertyand defaults to None.
- helper_text#
Helper text when entering an invalid date.
helper_textis anStringPropertyand 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.
dayis anNumericPropertyand 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.
monthis anNumericPropertyand 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.
yearis anNumericPropertyand defaults to 0.
- min_year#
The year of month to be opened by default. If not specified, the current number will be used.
min_yearis anNumericPropertyand defaults to 1914.
- max_year#
The year of month to be opened by default. If not specified, the current number will be used.
max_yearis anNumericPropertyand 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’].
modeis anOptionPropertyand 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_dateis anObjectPropertyand 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_dateis anObjectPropertyand 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_erroris anStringPropertyand defaults to ‘Error date range’.
- input_field_cls#
A class that will implement date input in the format dd/mm/yyyy. See
DatePickerInputFieldclass 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_clsis anObjectPropertyand defaults toDatePickerInputField.
- 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.
- transformation_from_dialog_select_year(self)#
- transformation_to_dialog_select_year(self)#
- transformation_to_dialog_input_date(self)#
- 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)#