从 Kivy MDTimePicker 中获取时间

Get the time out of Kivy MDTimePicker

我是 Kivy 和小部件绑定的新手。 我在 Github 上找到了以下代码,它提供了一个带有漂亮时钟的时间选择器。

应该很简单,但我只是不知道如何修改程序来简单地打印出时间。

from kivy.lang import Builder
from kivymd.app import MDApp
from kivymd.uix.picker import MDTimePicker

KV = '''
FloatLayout:
    MDRaisedButton:
        text: "Time 1"
        pos_hint: {'x': .1, 'y': .95}
        on_release: app.show_time_picker1()
'''
class Clock(MDApp):
    def build(self):
        return Builder.load_string(KV)

    def show_time_picker1(self):
        '''Open time picker dialog.'''
        time_dialog1 = MDTimePicker()
        time_dialog1.bind(time=self.get_time)
        time_dialog1.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

Clock().run()

只需在get_time()方法中添加一个print即可:

def get_time(self, instance, time):
    '''
    The method returns the set time.
    :type instance: <kivymd.uix.picker.MDTimePicker object>
    :type time: <class 'datetime.time'>
    '''
    print('picked time is', time)
    return time