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. So In this article we will learn how can we use the images as the button using the .kv file functionality and also give some styling to the button. But before we start, let’s learn some properties of button –
background_down : Background image of the button used for the default graphical representation when the button is pressed.
background_normal : Background image of the button used for the default graphical representation when the button is not pressed.
background_disabled_normal : Background image of the button used for the default graphical representation when the button is disabled and not pressed.
These all 3 properties are a StringProperty that means they only takes string as values.
To use button you must have to import :
import kivy.uix.button as Button
Basic Approach: 1) import kivy 2) import kivyApp 3) import button 4) import FloatLayout 5) set minimum version(optional) 6) Create the Layout class 7) Create App class 8) Create .kv file: 1) Add Base class 2) Add Button properties 3) Add Image as button 4) Resizing, Positioning, functionality etc of Imagebutton 9) return instance of the layout class 10) Run an instance of the class
Image used in this this article –
When button not pressed
When button is pressed
- Use image as a button in kivy
- Disable kivy button using .kv file
- Python | Toggle button in kivy using .kv file
- Python - Change button color in kivy using .kv file
- Python - Rounding button corners in kivy using .kv file
- Text Input box with a verification button in kivy (using .kv file)
- Circular (Oval like) button using canvas in kivy (using .kv file)
- Python - Change kivy button size and position using kv file
- Python | Adding image in Kivy using .kv file
- Disable Kivy Button
- Change button Color in Kivy
- Python | Button Action in Kivy
- Python - Rounding button corners in kivy
- Text Input box with a verification button in kivy
- Change the size and position of button in Kivy
- Floating Action type button in kivy - Python
- Animated Floating Action Button in kivy - Python
- Python | Kivy .kv File
- Python | Add image widget in Kivy
- Python | ScreenManager in Kivy using .kv file
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.