【发布时间】:2019-06-25 04:32:11
【问题描述】:
我制作了一个简单的应用程序,它有两个同时运行的计时器。一个向上计数,另一个向下计数。
我最初尝试在Label下缩进声明“text:str(round(self.a,1))”,并且会出现标题中所述的错误。我现在已经通过调整我的代码解决了这个问题,如下所示(更改是在最后的 .kv 文件部分中进行的):
from kivy.app import App
from kivy.uix.label import Label
from kivy.animation import Animation
from kivy.properties import NumericProperty
from random import randint
from kivy.uix.boxlayout import BoxLayout
class PleaseWork(BoxLayout):
a = NumericProperty(randint(3,7))
b = NumericProperty(0)
def start(self):
self.anim = Animation(a=0, duration=self.a)
self.anim &= Animation(b=15, duration=15)
self.anim.repeat = True
self.anim.start(self)
class PleaseApp(App):
def build(self):
p = PleaseWork()
p.start()
return p
if __name__ == "__main__":
PleaseApp().run()
<PleaseWork>
orientation: 'vertical'
text_1: str(round(self.a, 1))
text_2: str(round(self.b, 1))
Label:
text: root.text_1
Label:
id: count_up
text: root.text_2
虽然代码现在做了它应该做的事情,但我的问题是为什么这纠正了错误?我真的不明白为什么这会有所作为?
【问题讨论】:
标签: python kivy kivy-language