TimePicker

Includes time 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 MDTimePicker

KV = '''
MDFloatLayout:

    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.png

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()

Note

For customization of the MDTimePicker class, see the documentation in the BaseDialogPicker class.

API - kivymd.uix.pickers.timepicker.timepicker

class kivymd.uix.pickers.timepicker.timepicker.MDTimePicker(**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.

hour

Current hour

hour is an StringProperty and defaults to ‘12’.

minute

Current minute

minute is an StringProperty and defaults to 0.

minute_radius

Radius of the minute input field.

minute_radius is an ListProperty and defaults to [dp(5),].

hour_radius

Radius of the hour input field.

hour_radius is an ListProperty and defaults to [dp(5),].

am_pm_radius

Radius of the AM/PM selector.

am_pm_radius is an NumericProperty and defaults to dp(5).

am_pm_border_width

Width of the AM/PM selector’s borders.

am_pm_border_width is an NumericProperty and defaults to dp(1).

am_pm

Current AM/PM mode.

am_pm is an OptionProperty and defaults to ‘am’.

animation_duration

Duration of the animations.

animation_duration is an NumericProperty and defaults to 0.2.

animation_transition

Transition type of the animations.

animation_transition is an StringProperty and defaults to ‘out_quad’.

time

Returns the current time object.

time is an ObjectProperty and defaults to None.

set_time(self, time_obj)

Manually set time dialog with the specified time.

get_state(self)

Returns the current state of TimePicker. Can be one of portrait, landscape or input.