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.
Now in this article, we will learn about how can we create the type of button similar to floating action button using kivy python.
What is Floating Action Button ??
A floating action button (FAB) performs the primary, or most common, action on a screen. It appears in front of all screen content, typically as a circular shape with an icon in its center.
To learn how to create this you must have the good knowledge about the Layouts, Button, canvas and Ellipse in canvas. These all we are going to use to create the button. So We are creating a button like the one we see on gmail on the right side i.e for writing a new email in mobile Application (not on website) sign.

Basic Approach:
1) import kivy
2) import kivyApp
3) import Boxlayout
4) Set minimum version(optional)
5) create Layout class
6) create App class
7) Set up .kv file :
1) Add Floating Button Properties
2) Create Main Window
3) Add Float Button
8) return Layout/widget/Class(according to requirement)
9) Run an instance of the class
Kivy Tutorial – Learn Kivy with Examples.
Implementation of the Approach –
main.py
Python3
import kivy
from kivy.app import App
from kivy.uix.boxlayout import BoxLayout
from kivy.config import Config
Config. set ( 'graphics' , 'resizable' , True )
class MainWindow(BoxLayout):
pass
class MainApp(App):
def build( self ):
return MainWindow()
if __name__ = = '__main__' :
MainApp().run()
|
.kv file implementation
main.kv
Python3
<FloatButton@FloatLayout>
id : float_root
size_hint: ( None , None )
text: ''
btn_size: ( 70 , 70 )
size: ( 70 , 70 )
bg_color: ( 0.404 , 0.227 , 0.718 , 1.0 )
pos_hint: { 'x' : . 6 }
Button:
text: float_root.text
markup: True
font_size: 40
size_hint: ( None , None )
size: float_root.btn_size
pos_hint: { 'x' : 5.5 , 'y' : 3.8 }
background_normal: ''
background_color: ( 0 , 0 , 0 , 0 )
canvas.before:
Color:
rgba: ( 0.404 , 0.227 , 0.718 , 1.0 )
Ellipse:
size: self .size
pos: self .pos
<MainWindow>:
BoxLayout:
FloatButton:
text: '+'
markup: True
background_color: 1 , 0 , 1 , 0
|
Output:

