【发布时间】:2015-05-27 21:26:09
【问题描述】:
我目前正在使用 Kivy 和 Python 编写一些代码。我正在尝试这样做,当您单击按钮时,按钮的文本会改变颜色。
但是,当我单击按钮时,颜色并不像我想要的那样。
有什么办法可以解决这个问题吗?我只是在学习 Kivy,也许答案比我想象的要容易。 .py 文件在下面
from kivy.app import App
from kivy.uix.widget import Widget
from kivy.properties import ObjectProperty
from kivy.uix.button import Button
from kivy.graphics import Color
class TextBubbleSample(Widget):
bubble = ObjectProperty(None)
class TextBubble(Widget):
pass
class Talk(Button):
btn = Button
def button_press(self):
btn.bind(on_state = self.on_event)
def on_event(self):
btn.color = 1,0,0,1
class TextBubbleApp(App):
def build(self):
return TextBubbleSample()
if __name__ == '__main__':
TextBubbleApp().run()
and here is the .kv file
#:kivy 1.0.9
<TextBubbleSample>:
bubble: text_bubble
btn: click_here
TextBubble:
id: text_bubble
x: root.x
center_y: root.center_y
Talk:
id: click_here
x: 10
center_y: 220
text: "Talk to me."
color: 0,0,1,1
<TextBubble>:
canvas:
Color:
rgba: 1,0,0,1
Rectangle:
pos: 10, 10
size: 780, 150
Label:
color: 0,0,1,1
font_size: 35
center_x: 200
top: root.top - 200
text: "I am talking"
【问题讨论】: