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):
self.theme_cls.theme_style = "Dark"
self.theme_cls.primary_palette = "Orange"
return Builder.load_string(KV)
def show_time_picker(self):
'''Open time picker dialog.'''
time_dialog = MDTimePicker()
time_dialog.open()
Test().run()
from kivymd.app import MDApp
from kivymd.uix.button import MDRaisedButton
from kivymd.uix.pickers import MDTimePicker
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 time picker",
pos_hint={'center_x': .5, 'center_y': .5},
on_release=self.show_time_picker,
)
)
)
def show_time_picker(self, *args):
'''Open time picker dialog.'''
MDTimePicker().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.MDTimePicker(
primary_color="brown",
accent_color="red",
text_button_color="white",
).open()
API - kivymd.uix.pickers.timepicker.timepicker
#
- class kivymd.uix.pickers.timepicker.timepicker.MDTimePicker(**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.
- hour#
Current hour.
hour
is anStringProperty
and defaults to ‘12’.
- minute#
Current minute.
minute
is anStringProperty
and defaults to 0.
- minute_radius#
Radius of the minute input field.
minute_radius
is anListProperty
and defaults to [dp(5), dp(5), dp(5), dp(5)].
- hour_radius#
Radius of the hour input field.
hour_radius
is anListProperty
and defaults to [dp(5), dp(5), dp(5), dp(5)].
- am_pm_radius#
Radius of the AM/PM selector.
am_pm_radius
is anNumericProperty
and defaults to dp(5).
- am_pm_border_width#
Width of the AM/PM selector’s borders.
am_pm_border_width
is anNumericProperty
and defaults to dp(1).
- am_pm#
Current AM/PM mode.
am_pm
is anOptionProperty
and defaults to ‘am’.
- animation_duration#
Duration of the animations.
animation_duration
is anNumericProperty
and defaults to 0.2.
- animation_transition#
Transition type of the animations.
animation_transition
is anStringProperty
and defaults to ‘out_quad’.
- time#
Returns the current time object.
time
is anObjectProperty
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.