1. <legend id='wuKQe'><style id='wuKQe'><dir id='wuKQe'><q id='wuKQe'></q></dir></style></legend>

        • <bdo id='wuKQe'></bdo><ul id='wuKQe'></ul>
      2. <i id='wuKQe'><tr id='wuKQe'><dt id='wuKQe'><q id='wuKQe'><span id='wuKQe'><b id='wuKQe'><form id='wuKQe'><ins id='wuKQe'></ins><ul id='wuKQe'></ul><sub id='wuKQe'></sub></form><legend id='wuKQe'></legend><bdo id='wuKQe'><pre id='wuKQe'><center id='wuKQe'></center></pre></bdo></b><th id='wuKQe'></th></span></q></dt></tr></i><div id='wuKQe'><tfoot id='wuKQe'></tfoot><dl id='wuKQe'><fieldset id='wuKQe'></fieldset></dl></div>

        <small id='wuKQe'></small><noframes id='wuKQe'>

        <tfoot id='wuKQe'></tfoot>

        Kivy/Python Countdown App 项目 kivy 没有属性 'built

        时间:2023-10-09
          <bdo id='yNAea'></bdo><ul id='yNAea'></ul>
          <legend id='yNAea'><style id='yNAea'><dir id='yNAea'><q id='yNAea'></q></dir></style></legend>

            <i id='yNAea'><tr id='yNAea'><dt id='yNAea'><q id='yNAea'><span id='yNAea'><b id='yNAea'><form id='yNAea'><ins id='yNAea'></ins><ul id='yNAea'></ul><sub id='yNAea'></sub></form><legend id='yNAea'></legend><bdo id='yNAea'><pre id='yNAea'><center id='yNAea'></center></pre></bdo></b><th id='yNAea'></th></span></q></dt></tr></i><div id='yNAea'><tfoot id='yNAea'></tfoot><dl id='yNAea'><fieldset id='yNAea'></fieldset></dl></div>
            • <small id='yNAea'></small><noframes id='yNAea'>

            • <tfoot id='yNAea'></tfoot>
                  <tbody id='yNAea'></tbody>
                  本文介绍了Kivy/Python Countdown App 项目 kivy 没有属性 'built' 错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  问题:什么是没有属性已构建"错误,我需要做什么来更正此代码,以便它可以接收日期时间对象并显示倒计时?抱歉,帖子太长了.

                  Question: What is a 'has no attribute 'built' error, and what do I need to do to correct this code so that it can take in a datetime object and display the count down? Sorry for the long post.

                  我已经提供了代码和 .kv 文件的链接.

                  I've provided the code and a link to the .kv file.

                  我尝试创建一个倒计时时钟,它将 datetime 对象作为参数并倒计时到该日期(使用 python 和 kivy).它基本上是对 Adam Giermanowski 的倒计时教程.

                  I tried to create a countdown clock that takes a datetime object as a parameter and counts down to that date (using python and kivy). It's basically an slight adaptation of Adam Giermanowski's countdown timer tutorial.

                  这是我的代码:

                  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() 行的错误:

                  Here's the error on the Counter(b).run() line:

                  AttributeError: 'Counter' object has no attribute 'built'
                  

                  推荐答案

                  你必须在重写 __init__ 时调用超类的构造函数,这样构造函数所做的所有事情才能拥有课堂作业的其他方法已完成.你的 init 方法应该是这样的:

                  You have to call the superclasses constructor when you override __init__, so that all of the things that that constructor does in order to have the other methods of the class work gets done. Your init method should be this:

                  def __init__(self, datetimeOBJ):
                      App.init(self)
                      self.datetimeOBJ = datetimeOBJ 
                  

                  这篇关于Kivy/Python Countdown App 项目 kivy 没有属性 'built' 错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:Python,Kivy,“AssertionError: None is not callable"按 下一篇:如何在 Kivy GUI 旁边运行 Tornado 事件循环?

                  相关文章

                  最新文章

                  <i id='OSvfl'><tr id='OSvfl'><dt id='OSvfl'><q id='OSvfl'><span id='OSvfl'><b id='OSvfl'><form id='OSvfl'><ins id='OSvfl'></ins><ul id='OSvfl'></ul><sub id='OSvfl'></sub></form><legend id='OSvfl'></legend><bdo id='OSvfl'><pre id='OSvfl'><center id='OSvfl'></center></pre></bdo></b><th id='OSvfl'></th></span></q></dt></tr></i><div id='OSvfl'><tfoot id='OSvfl'></tfoot><dl id='OSvfl'><fieldset id='OSvfl'></fieldset></dl></div>
                    • <bdo id='OSvfl'></bdo><ul id='OSvfl'></ul>

                      <small id='OSvfl'></small><noframes id='OSvfl'>

                      <tfoot id='OSvfl'></tfoot>
                      <legend id='OSvfl'><style id='OSvfl'><dir id='OSvfl'><q id='OSvfl'></q></dir></style></legend>