TimePicker#
See also Includes time picker. Warning The widget is under testing. Therefore, we would be grateful if
you would let us know about the bugs found. Usage Use the Note For customization of the
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()
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#
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()
MDTimePicker class, see the
documentation in the BaseDialogPicker class.time_dialog = MDTimePicker(
primary_color=get_color_from_hex("#72225b"),
accent_color=get_color_from_hex("#5d1a4a"),
text_button_color=(1, 1, 1, 1),
)
.. image:: https://github.com/HeaTTheatR/KivyMD-data/raw/master/gallery/kivymddoc/time-picker-customization.png
:align: center
API - kivymd.uix.pickers.timepicker.timepicker#
- class kivymd.uix.pickers.timepicker.timepicker.MDTimePicker(**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.
- hour#
Current hour.
houris anStringPropertyand defaults to ‘12’.
- minute#
Current minute.
minuteis anStringPropertyand defaults to 0.
- minute_radius#
Radius of the minute input field.
minute_radiusis anListPropertyand defaults to [dp(5), dp(5), dp(5), dp(5)].
- hour_radius#
Radius of the hour input field.
hour_radiusis anListPropertyand defaults to [dp(5), dp(5), dp(5), dp(5)].
- am_pm_radius#
Radius of the AM/PM selector.
am_pm_radiusis anNumericPropertyand defaults to dp(5).
- am_pm_border_width#
Width of the AM/PM selector’s borders.
am_pm_border_widthis anNumericPropertyand defaults to dp(1).
- am_pm#
Current AM/PM mode.
am_pmis anOptionPropertyand defaults to ‘am’.
- animation_duration#
Duration of the animations.
animation_durationis anNumericPropertyand defaults to 0.2.
- animation_transition#
Transition type of the animations.
animation_transitionis anStringPropertyand defaults to ‘out_quad’.
- time#
Returns the current time object.
timeis anObjectPropertyand 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.