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.
In this article we will going to learn how to round the button corners in kivy using .kv file in Python.
Widgets are always rectangle, but we can change the background of widgets and put couple of images for the normal and the down state of the button by using some properties of buttons like
background_down properties respectively. Also, to round the corners of the button you also must have understand one more property of button that is the border property.
1) Background image of the button used for the default graphical representation when the button is pressed.
2) background_down is a StringProperty .
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
1) Border used for BorderImage graphics instruction. Used with background_normal and background_down. Can be used for custom backgrounds.
2) It must be a list of four values: (bottom, right, top, left).
3) border is a ListProperty and defaults to (16, 16, 16, 16)
Syntax of all above properties:
Basic Approach: 1) import kivy 2) import kivyApp 3) import button and floatlayout 4) set minimum version(optional) 5) Create the Layout class 6) Create App class 7) Create .kv file: 1) Add Base class 2) Add Button properties 3) Add Image as button 4) Round the corners of the button using border property 8) return instance of the layout class 9) Run an instance of the class
Below is the two images that is used by me in this i.e:
normal.png and down.png
Now below is the code implementing my approach:
- Python - Rounding button corners in kivy
- Python | Toggle button in kivy using .kv file
- Python - Change button color in kivy using .kv file
- Python - Change kivy button size and position using kv file
- Add image button using .kv file in kivy
- Disable kivy button using .kv file
- Circular (Oval like) button using canvas in kivy (using .kv file)
- Text Input box with a verification button in kivy (using .kv file)
- Python | Button Action in Kivy
- Animated Floating Action Button in kivy - Python
- Floating Action type button in kivy - Python
- Python | Kivy .kv File
- Python | PageLayout in Kivy using .kv file
- Python | Accordion in kivy using .kv file
- Python | ScreenManager in Kivy using .kv file
- Python | FloatLayout in Kivy using .kv file
- Python | File chooser in kivy
- Python | StackLayout in Kivy using .kv file
- Python | AnchorLayout in Kivy using .kv file
- Python | Canvas 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.