问题:什么是“没有属性”构建”错误,我需要做什么来更正此代码,以便它可以接受日期时间对象并显示倒计时?抱歉发了这么长的帖子。
我已经提供了代码和链接.kv 文件 https://github.com/tmusa/CySat-GroundStation/blob/develop/Counter.kv.
我尝试创建一个倒计时时钟,它将日期时间对象作为参数并倒计时到该日期(使用 python 和 kivy)。基本上是一个轻微的改编亚当·吉尔曼诺夫斯基 http://chilliq.github.io/kivy%20python/2014/08/11/simple-kivy-countdown-app.html的倒计时器教程。
这是我的代码:
from kivy.app import App
from kivy.uix.label import Label
from kivy.uix.boxlayout import BoxLayout
from kivy.properties import StringProperty
from kivy.clock import Clock
import datetime
#datetime object
b= datetime.datetime(2016,9,12,3,5)
class Counter_Timer(BoxLayout):
days = StringProperty()
hours = StringProperty()
minutes = StringProperty()
seconds = StringProperty()
def __init__(self, datetimeOBJ):
self.datetimeOBJ = datetimeOBJ
def update(self, dt):
#the difference in time
delta = self.datetimeOBJ - datetime.datetime.now()
self.days = str(delta.days)
hour_string = str(delta).split(', ')[1]
self.hours = hour_string.split(':')[0]
self.minutes = hour_string.split(':')[1]
self.seconds = hour_string.split(':')[2].split('.')[0]
class Counter(App):
#takes a datetime object as a parameter
def __init__(self, datetimeOBJ):
self.datetimeOBJ = datetimeOBJ
def build(self):
Counter = Counter_Timer(self.datetimeOBJ)
Clock.schedule_interval(Counter.update, 1.0)
return Counter
if __name__=='__main__':
Counter(b).run()
这是 Counter(b).run() 行上的错误:
AttributeError: 'Counter' object has no attribute 'built'