问题在.kv文件中。我的问题是我希望我的.kv注意到我的.py中的object属性。如果将.kv中的颜色更改为color: 0,0,0
,则我的代码可以正常工作,这将按预期提供黑色文本
白痴
from kivy import utils
from kivy.animation import Animation
from kivy.clock import Clock
from kivy.properties import ObjectProperty
from kivy.uix.label import Label
from kivy.lang import Builder
from kivy.uix.button import ButtonBehavior
Builder.load_file("FirebaseLoginScreen/themedwidgets.kv")
class ThemedButton(ButtonBehavior,Label):
colorchanged = ObjectProperty()
color = ObjectProperty([0,0,0,1])
def __init__(self, **kwargs):
super(ThemedButton, self).__init__(**kwargs)
Clock.schedule_once(self.start_pulsing, 1)
def start_pulsing(self, *args):
anim = Animation(color=[0,1,0,1]) + Animation(color=[0,0,1,1]) + Animation(color=[1,0,0,1])
anim.repeat = True
anim.start(self)
.kv
<ThemedButton@ButtonBehavior+Label>:
colorchanged: colorchanged
id: colorchanged
markup: True
color: self.color #root.color doesn't work either but 0,0,0 does give me black.
opacity: 1 if self.state == 'normal' else .8
font_size: 38
这是创建一个继承自ButtonHavior和Label的新小部件类的kv语法,因此它没有任何Python定义的类的行为恰好具有相同的名称
你只想做
<ThemedButton>:
相关问题 更多 >
编程相关推荐