This is how I would do it ...
''' kivy_button_label101.py
create a touch sensitive button with Python module kivy
add a label to show action
info:
http://kivy.org/docs/api-kivy.uix.button.html
http://kivy.org/docs/api-kivy.uix.label.html
http://kivy.org/docs/api-kivy.uix.boxlayout.html
'''
from kivy.app import App
from kivy.uix.button import Button
from kivy.uix.label import Label
from kivy.uix.boxlayout import BoxLayout
class TestApp(App):
def build(self):
layout = BoxLayout(orientation='vertical')
# use a (r, g, b, a) tuple
blue = (0, 0, 1.5, 2.5)
red = (2.5, 0, 0, 1.5)
btn = Button(text='Touch me!', background_color=blue, font_size=120)
btn.bind(on_press=self.callback)
self.label = Label(text="------------", font_size='50sp')
layout.add_widget(btn)
layout.add_widget(self.label)
return layout
def callback(self, event):
print("button touched") # test
self.label.text = "button touched"
TestApp().run()