Button

_images/button.jpg

Button is a Label with associated actions that are triggered when the button is pressed (or released after a click/touch). To configure the button, you can use the same properties that you can use for the Label class:

button = Button(text='Hello world', font_size=14)

To attach a callback when the button is pressed (clicked/touched), use bind:

def callback(instance):
    print 'The button <%s> is being pressed' % instance.text

btn1 = Button(text='Hello world 1')
btn1.bind(on_press=callback)
btn2 = Button(text='Hello world 2')
btn2.bind(on_press=callback)

If you want to be notified every time the button state changes, you can attach to the Button.state property:

def callback(instance, value):
    print 'My button <%s> state is <%s>' % (instance, value)
btn1 = Button(text='Hello world 1')
btn1.bind(state=callback)
class kivy.uix.button.Button(**kwargs)

Bases: kivy.uix.label.Label

Button class, see module documentation for more information.

Events :
on_press

Fired when the button is pressed.

on_release

Fired when the button is released (i.e., the touch/click that pressed the button goes away).

background_color

Background color, in the format (r, g, b, a).

New in version 1.0.8.

background_color is a ListProperty, default to [1, 1, 1, 1].

background_down

Background image of the button used for default graphical representation, when the button is pressed.

New in version 1.0.4.

background_down is an StringProperty, default to ‘atlas://data/images/defaulttheme/button_pressed’

background_normal

Background image of the button used for default graphical representation, when the button is not pressed.

New in version 1.0.4.

background_normal is an StringProperty, default to ‘atlas://data/images/defaulttheme/button’

border

Border used for BorderImage graphics instruction. Used with background_normal and background_down. Can be used for a custom background.

It must be a list of four values: (top, right, bottom, left). Read the BorderImage instruction for more information about how to use it.

border is a ListProperty, default to (16, 16, 16, 16)

state

State of the button, must be one of ‘normal’ or ‘down’. The state is ‘down’ only when the button is currently touched/clicked, otherwise ‘normal’.

state is an OptionProperty.