Python Kivy中的定时横幅问候
我正试图建立一个横幅,将显示在一个按钮在Kivy在早上说“早上好”,下午说“下午好”,晚上说“晚上好”。我很难解决这个问题。到目前为止,我的代码是这样的: 在.py文件中:Python Kivy中的定时横幅问候,python,time,kivy,kivy-language,Python,Time,Kivy,Kivy Language,我正试图建立一个横幅,将显示在一个按钮在Kivy在早上说“早上好”,下午说“下午好”,晚上说“晚上好”。我很难解决这个问题。到目前为止,我的代码是这样的: 在.py文件中: class Personal_Assistant(BoxLayout): time_stamp = 0 morning = 'Good Morning' afternoon = 'Good Afternoon' evening = 'Good even
class Personal_Assistant(BoxLayout):
time_stamp = 0
morning = 'Good Morning'
afternoon = 'Good Afternoon'
evening = 'Good even'
name = 'James'
def timer(self):
self.now = datetime.datetime.now()
if self.now > 5 and self.now <12:
return self.morning, 'James'
elif self.now > 12 and self.now < 5:
return self.afternoon, 'James'
elif self.now > 5 and self.now < 12:
return self.evening, 'James'
只需使用hour属性即可
self.now = datetime.datetime.now().hour
我不知道如何以小时为单位获取当前时间,但我已经尝试使用依赖于小时数的if语句
self.now = datetime.datetime.now().hour