Change button Color in Kivy (original) (raw)

Last Updated : 9 Oct, 2025

A Button’s color in Kivy is controlled by the background_color property (an RGBA tuple with values from 0 to 1). This article shows examples that demonstrate how to set a button color and change it at runtime.

This example creates a minimal app with a single red button.

Python `

from kivy.app import App from kivy.uix.button import Button

class BasicColorApp(App): def build(self): b = Button(text='Red', background_normal='', background_color=(1,0,0,1)) return b

if name == 'main': BasicColorApp().run()

`

**Output

BasicButtonColorOutput

BasicColor

**Explanation:

Syntax

Button( text='OK', background_normal='', background_color=(r,g,b,a), color=(r,g,b,a), size_hint=(None,None), size=(w,h), on_press=callback, on_release=callback )

**Parameters:

Examples

**Example 1: This code shows two side-by-side buttons with different flat colors.

Python `

from kivy.app import App from kivy.uix.boxlayout import BoxLayout from kivy.uix.button import Button

class TwoColorsApp(App): def build(self): r = BoxLayout(orientation='horizontal', spacing=10, padding=10) r.add_widget(Button(text='Blue', background_normal='', background_color=(0,0.7,1,1))) r.add_widget(Button(text='Green', background_normal='', background_color=(0,0.8,0.3,1))) return r

if name == 'main': TwoColorsApp().run()

`

**Output

ButtonColorEx1Output

Two Color

**Explanation:

**Example 2: This code assigns a random flat color to the button each time it is released.

Python `

from kivy.app import App from kivy.uix.button import Button import random

class RandomColorApp(App): def build(self): b = Button(text='Random', background_normal='', background_color=(0.5,0.5,0.5,1)) def on_release(inst): inst.background_color = (random.random(), random.random(), random.random(), 1) b.bind(on_release=on_release) return b

if name == 'main': RandomColorApp().run()

`

**Output

ButtonColorEx2Output1

Random Color

ButtonColorEx2Output2

Random Color

**Explanation: