我想在跑步时改变画布的颜色。在
画布的颜色应为:
len(inputtext)%3 == 0
len(inputtext)%3 == 1
len(inputtext)%3 == 2
我不知道如何在下面的代码中编写color()
方法:
kv ="""
RootWidget:
orientation: 'vertical'
TextInput:
id: my_id
text: 'text'
on_text: root.color()
Label:
id: my_Label
text: ' '
canvas.before:
Color:
rgb: (1., 1., 0.)
Rectangle:
size: self.size
pos: self.pos
"""
import kivy
kivy.require('1.8.0')
from kivy.app import App
from kivy.lang import Builder
from kivy.uix.boxlayout import BoxLayout
class RootWidget(BoxLayout):
def __init__(self):
super().__init__()
def color(self):
pass # <-- here
class TestApp(App):
def build(self):
return Builder.load_string(kv)
if __name__ == '__main__':
TestApp().run()
这里有一个解决方案:)只需添加一个属性来定义标签的颜色(以千伏为单位)。然后在
color
-方法中相应地设置这个属性。在相关问题 更多 >
编程相关推荐