DatePicker#
See also Includes date picker. 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:
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):
self.theme_cls.theme_style = "Dark"
self.theme_cls.primary_palette = "Orange"
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()
from kivymd.app import MDApp
from kivymd.uix.button import MDRaisedButton
from kivymd.uix.pickers import MDDatePicker
from kivymd.uix.screen import MDScreen
class Test(MDApp):
def build(self):
self.theme_cls.theme_style = "Dark"
self.theme_cls.primary_palette = "Orange"
return (
MDScreen(
MDRaisedButton(
text="Open data picker",
pos_hint={'center_x': .5, 'center_y': .5},
on_release=self.show_date_picker,
)
)
)
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, *args):
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.today(),
max_date=datetime.date(
datetime.date.today().year,
datetime.date.today().month,
datetime.date.today().day + 2,
),
)
date_dialog.open()
Select year#
min_year
and
max_year
attributes:def show_date_picker(self):
date_dialog = MDDatePicker(min_year=2022, 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
MDDatePicker
andMDTimePicker
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")
title_input
is anStringProperty
and defaults to INPUT DATE.
- title#
Dialog title fot select date.
MDDatePicker(title="SELECT DATE")
title
is anStringProperty
and defaults to SELECT DATE.
- radius#
Radius list for the four corners of the dialog.
MDDatePicker(radius=[7, 7, 7, 26])
radius
is anListProperty
and defaults to [7, 7, 7, 7].
- primary_color#
Background color of toolbar in (r, g, b, a) or string format.
MDDatePicker(primary_color="brown")
primary_color
is anColorProperty
and defaults to None.
- accent_color#
Background color of calendar/clock face in (r, g, b, a) or string format.
MDDatePicker( primary_color="brown", accent_color="darkred", )
accent_color
is anColorProperty
and defaults to None.
- selector_color#
Background color of the selected day of the month or hour in (r, g, b, a) or string format.
MDDatePicker( primary_color="brown", accent_color="darkred", selector_color="red", )
selector_color
is anColorProperty
and defaults to None.
- text_toolbar_color#
Color of labels for text on a toolbar in (r, g, b, a) or string format.
MDDatePicker( primary_color="brown", accent_color="darkred", selector_color="red", text_toolbar_color="lightgrey", )
text_toolbar_color
is anColorProperty
and defaults to None.
- text_color#
Color of text labels in calendar/clock face in (r, g, b, a) or string format.
MDDatePicker( primary_color="brown", accent_color="darkred", selector_color="red", text_toolbar_color="lightgrey", text_color="orange", )
text_color
is anColorProperty
and defaults to None.
- text_current_color#
Color of the text of the current day of the month/hour in (r, g, b, a) or string format.
MDDatePicker( primary_color="brown", accent_color="darkred", selector_color="red", text_toolbar_color="lightgrey", text_color="orange", text_current_color="white", )
text_current_color
is anColorProperty
and defaults to None.
- text_button_color#
Text button color in (r, g, b, a) format.
MDDatePicker( primary_color="brown", accent_color="darkred", selector_color="red", text_toolbar_color="lightgrey", text_color="orange", text_current_color="white", text_button_color="lightgrey", )
text_button_color
is anColorProperty
and defaults to None.
- input_field_background_color_normal#
Background color normal of input fields in (r, g, b, a) or string format.
New in version 1.1.0.
MDDatePicker( primary_color="brown", accent_color="darkred", selector_color="red", text_toolbar_color="lightgrey", text_color="orange", text_current_color="white", text_button_color="lightgrey", input_field_background_color_normal="coral", )
input_field_background_color_normal
is anColorProperty
and defaults to None.
- input_field_background_color_focus#
Background color normal of input fields in (r, g, b, a) or string format.
New in version 1.1.0.
MDDatePicker( primary_color="brown", accent_color="darkred", selector_color="red", text_toolbar_color="lightgrey", text_color="orange", text_current_color="white", text_button_color="lightgrey", input_field_background_color_normal="coral", input_field_background_color_focus="red", )
input_field_background_color_focus
is anColorProperty
and defaults to None.
- input_field_background_color#
Deprecated since version 1.1.0.
Use
input_field_background_color_normal
instead.
- input_field_text_color#
Deprecated since version 1.1.0.
Use
input_field_text_color_normal
instead.
- input_field_text_color_normal#
Text color normal of input fields in (r, g, b, a) or string format.
New in version 1.1.0.
MDDatePicker( primary_color="brown", accent_color="darkred", selector_color="red", text_toolbar_color="lightgrey", text_color="orange", text_current_color="white", text_button_color="lightgrey", input_field_background_color_normal="brown", input_field_background_color_focus="red", input_field_text_color_normal="white", )
input_field_text_color_normal
is anColorProperty
and defaults to None.
- input_field_text_color_focus#
Text color focus of input fields in (r, g, b, a) or string format.
New in version 1.1.0.
MDDatePicker( primary_color="brown", accent_color="darkred", selector_color="red", text_toolbar_color="lightgrey", text_color="orange", text_current_color="white", text_button_color="lightgrey", input_field_background_color_normal="brown", input_field_background_color_focus="red", input_field_text_color_normal="white", )
input_field_text_color_focus
is anColorProperty
and defaults to None.
- font_name#
Font name for dialog window text.
MDDatePicker( primary_color="brown", accent_color="darkred", selector_color="red", text_toolbar_color="lightgrey", text_color="orange", text_current_color="white", text_button_color="lightgrey", input_field_background_color_normal="brown", input_field_background_color_focus="red", input_field_text_color_normal="white", input_field_text_color_focus="lightgrey", font_name="nasalization.ttf", )
font_name
is anStringProperty
and defaults to ‘Roboto’.
- on_input_field_background_color(self, instance, value: str | list | tuple)#
For supported of current API.
- 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(*args, **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
MDDatePicker
andMDTimePicker
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) or string format.
text_weekday_color
is anColorProperty
and defaults to None.
- helper_text#
Helper text when entering an invalid date.
helper_text
is anStringProperty
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 anNumericProperty
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 anNumericProperty
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 anNumericProperty
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 anNumericProperty
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 anNumericProperty
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 anOptionProperty
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 anObjectProperty
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 anObjectProperty
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 anStringProperty
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 anObjectProperty
and 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)#