从python到kivy的引用出错了

2024-09-29 23:15:11 发布

您现在位置:Python中文网/ 问答频道 /正文

问题在.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

Tags: fromimportselfstartlabelcolorkvkivy

热门问题