Pickers

Includes date, time and color picker

KivyMD provides the following classes for use:

MDTimePicker

Usage

from kivy.lang import Builder

from kivymd.app import MDApp
from kivymd.uix.picker import MDTimePicker

KV = '''
FloatLayout:

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


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

    def show_time_picker(self):
        '''Open time picker dialog.'''

        time_dialog = MDTimePicker()
        time_dialog.open()


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

Binding method returning set time

def show_time_picker(self):
    time_dialog = MDTimePicker()
    time_dialog.bind(time=self.get_time)
    time_dialog.open()

def get_time(self, instance, time):
    '''
    The method returns the set time.

    :type instance: <kivymd.uix.picker.MDTimePicker object>
    :type time: <class 'datetime.time'>
    '''

    return time

Open time dialog with the specified time

Use the set_time method of the class.

def show_time_picker(self):
    from datetime import datetime

    # Must be a datetime object
    previous_time = datetime.strptime("03:20:00", '%H:%M:%S').time()
    time_dialog = MDTimePicker()
    time_dialog.set_time(previous_time)
    time_dialog.open()
https://github.com/HeaTTheatR/KivyMD-data/raw/master/gallery/kivymddoc/previous-time.png

MDDatePicker

When creating an instance of the MDDatePicker class, you must pass as a parameter a method that will take one argument - a datetime object.

def get_date(self, date):
    '''
    :type date: <class 'datetime.date'>
    '''

def show_date_picker(self):
    date_dialog = MDDatePicker(callback=self.get_date)
    date_dialog.open()
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(
        callback=self.get_date,
        year=2010,
        month=2,
        day=12,
    )
    date_dialog.open()
https://github.com/HeaTTheatR/KivyMD-data/raw/master/gallery/kivymddoc/previous-date.png

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):
    min_date = datetime.strptime("2020:02:15", '%Y:%m:%d').date()
    max_date = datetime.strptime("2020:02:20", '%Y:%m:%d').date()
    date_dialog = MDDatePicker(
        callback=self.get_date,
        min_date=min_date,
        max_date=max_date,
    )
    date_dialog.open()
https://github.com/HeaTTheatR/KivyMD-data/raw/master/gallery/kivymddoc/range-date.png

MDThemePicker

def show_theme_picker(self):
    theme_dialog = MDThemePicker()
    theme_dialog.open()
https://github.com/HeaTTheatR/KivyMD-data/raw/master/gallery/kivymddoc/MDThemePicker.gif

API - kivymd.uix.picker

class kivymd.uix.picker.MDDatePicker(callback, year=None, month=None, day=None, firstweekday=0, min_date=None, max_date=None, **kwargs)

Bases: kivy.uix.floatlayout.FloatLayout, kivymd.theming.ThemableBehavior, kivymd.uix.behaviors.RectangularElevationBehavior, kivymd.uix.behaviors.SpecificBackgroundColorBehavior, kivy.uix.modalview.ModalView

cal_list
cal_layout
sel_year
sel_month
sel_day
day
month
year
today
callback
background_color
ok_click(self)
fmt_lbl_date(self, year, month, day, orientation)
set_date(self, year, month, day)
set_selected_widget(self, widget)
set_month_day(self, day)
update_cal_matrix(self, year, month)
generate_cal_widgets(self)
change_month(self, operation)
class kivymd.uix.picker.MDTimePicker(**kwargs)

Bases: kivymd.theming.ThemableBehavior, kivy.uix.floatlayout.FloatLayout, kivy.uix.modalview.ModalView, kivymd.uix.behaviors.RectangularElevationBehavior

time

Users method. Must take two parameters:

def get_time(self, instance, time):
    '''
    The method returns the set time.

    :type instance: <kivymd.uix.picker.MDTimePicker object>
    :type time: <class 'datetime.time'>
    '''

    return time

time is an ObjectProperty and defaults to None.

set_time(self, time)

Sets user time.

close_cancel(self)
close_ok(self)
class kivymd.uix.picker.MDThemePicker

Bases: kivymd.theming.ThemableBehavior, kivy.uix.floatlayout.FloatLayout, kivy.uix.modalview.ModalView, kivymd.uix.behaviors.SpecificBackgroundColorBehavior, kivymd.uix.behaviors.RectangularElevationBehavior