<legend id='Z5ncL'><style id='Z5ncL'><dir id='Z5ncL'><q id='Z5ncL'></q></dir></style></legend>
      <bdo id='Z5ncL'></bdo><ul id='Z5ncL'></ul>

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

  1. <tfoot id='Z5ncL'></tfoot>

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

    1. Kivy/Python Countdown App 项目 kivy 没有属性 'built' 错误

      时间:2023-06-07
        <tbody id='wYVPM'></tbody>
        <i id='wYVPM'><tr id='wYVPM'><dt id='wYVPM'><q id='wYVPM'><span id='wYVPM'><b id='wYVPM'><form id='wYVPM'><ins id='wYVPM'></ins><ul id='wYVPM'></ul><sub id='wYVPM'></sub></form><legend id='wYVPM'></legend><bdo id='wYVPM'><pre id='wYVPM'><center id='wYVPM'></center></pre></bdo></b><th id='wYVPM'></th></span></q></dt></tr></i><div id='wYVPM'><tfoot id='wYVPM'></tfoot><dl id='wYVPM'><fieldset id='wYVPM'></fieldset></dl></div>
          <bdo id='wYVPM'></bdo><ul id='wYVPM'></ul>

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

          <legend id='wYVPM'><style id='wYVPM'><dir id='wYVPM'><q id='wYVPM'></q></dir></style></legend>

              • <tfoot id='wYVPM'></tfoot>
              • 本文介绍了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' 错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

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

                相关文章

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

                    <small id='1b5DT'></small><noframes id='1b5DT'>