Kivy is a platform independent GUI tool in Python. As it can be run on Android, IOS, linux and Windows etc. It is basically used to develop the Android application, but it does not mean that it can not be used on Desktops applications. As we have discussed earlier that how to work with images and now in this we will gonna be learn how to use the images and create a button with them. In this article we will learn how can we use the image as button and how to add functionality and styling on that image.
To learn about it you must be aware about some properties, that are – background_down : 1) Background image of the button used for the default graphical representation when the button is pressed. 2) background_down is a StringProperty . background_normal : 1) Background image of the button used for the default graphical representation when the button is not pressed. 2) background_normal is also a StringProperty . background_disabled_normal : 1) Background image of the button used for the default graphical representation when the button is disabled and not pressed. 2) background_disabled_normal is also a StringProperty . Notes : 1) Now its only sufficient to understand that string property means they only take values in string that means like background_down: “normal.png” like this. 2) On click on the image it looks same like a simple button (as we uses it in a button).
Image used in this article are: normal.png:
down.png: 
Basic Approach :
-> import kivy
-> import kivy App
-> import button
-> set minimum version(optional)
-> Extend the class :
-> create an image a button
-> Do styling
-> Arrange call back if needed
-> Add and return a button
-> Run an instance of the class
Kivy Tutorial – Learn Kivy with Examples.
Simple Implementation that how to create a button using image
Python3
import kivy
kivy.require(" 1.9 . 1 ")
from kivy.app import App
from kivy.uix.button import Button
kivy.require( '1.9.0' )
from kivy.config import Config
Config. set ( 'graphics' , 'resizable' , True )
class ButtonApp(App):
def build( self ):
btn = Button(text = "Push Me !",
color = ( 1 , 0 , . 65 , 1 ),
background_normal = 'normal.png' ,
background_down = 'down.png' ,
size_hint = (. 3 , . 3 ),
pos_hint = {"x": 0.35 , "y": 0.3 }
)
return btn
root = ButtonApp()
root.run()
|
Output:
Code to implement the styling and arranging a callback to the button –
Python3
import kivy
kivy.require(" 1.9 . 1 ")
from kivy.app import App
from kivy.uix.button import Button
kivy.require( '1.9.0' )
from kivy.config import Config
Config. set ( 'graphics' , 'resizable' , True )
class ButtonApp(App):
def build( self ):
btn = Button(text = "Push Me !",
background_normal = 'normal.png' ,
background_down = 'down.png' ,
size_hint = (. 3 , . 3 ),
pos_hint = {"x": 0.35 , "y": 0.3 }
)
btn.bind(on_press = self .callback)
return btn
def callback( self , event):
print ("button pressed")
print ( 'Yoooo !!!!!!!!!!!' )
root = ButtonApp()
root.run()
|
Output:

Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape,
GeeksforGeeks Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we've already empowered, and we're here to do the same for you. Don't miss out -
check it out now!
Last Updated :
29 Jun, 2022
Like Article
Save Article