Open In App

Python | Bubble in kivy

Last Updated : 06 Feb, 2020
Like Article

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.

👉🏽 Kivy Tutorial – Learn Kivy with Examples.

Bubble :

The Bubble widget is a form of menu or a small popup where the menu options are stacked either vertically or horizontally. The Bubble contains an arrow pointing in the direction you choose.

To choose the direction in which arrow points use:


The orientation of the bubble is by default horizontally but you can change it by the command:

orientation = ‘vertical’

To add items to the bubble:

bubble = Bubble(orientation = ‘vertical’)

To remove items:


Basic Approach :
1) import kivy
2) import kivyApp
3) import Button
4) import Floatlayout(according to need)
5) import Bubble
6) import object property
7) Create Layout class:
8) Create App class
9) create .kv file (name same as the app class):
        1) createBubble
10) return Layout/widget/Class(according to requirement)
11) Run an instance of the class

# Implementation of the Approach:

# .py code:

# Program to Show how to create a switch 
# import kivy module    
import kivy  
# base Class of your App inherits from the App class.    
# app:always refers to the instance of your application   
from import App 
# this restrict the kivy version i.e  
# below this kivy version you cannot  
# use the app or software  
# module consists the floatlayout  
# to work with FloatLayout first  
# you have to import it  
from kivy.uix.floatlayout import FloatLayout
# The Button is a Label with associated
# actions that are triggered
# when the button is pressed 
from kivy.uix.button import Button
# The Bubble widget is a form of menu or a
# small popup where the menu options
# are stacked either vertically or horizontally.
from kivy.uix.bubble import Bubble
# ObjectProperty is a specialized sub-class of the
# Property class, so it has the same
# initialisation parameters as it:
# By default, a Property always takes a default value[.]
from import ObjectProperty
# Create the Bubble class
# on which the .kv file is
class Cut_copy_paste(Bubble):
# Create the Layout Class
class BubbleDemo(FloatLayout):
    def __init__(self, **kwargs):
        super(BubbleDemo, self).__init__(**kwargs)
        self.but_bubble = Button(text ='Press to show bubble')
        self.but_bubble.bind(on_release = self.show_bubble)
        self.bubb = Cut_copy_paste()
    # Defining the function to show the bubble
    def show_bubble(self, *l):
# Create the App class
class BubbleApp(App):
    def build(self):
        return BubbleDemo()
# run the App
if __name__ == '__main__':

.kv file:

# .kv file of the bubble
# Creating bubble
    size_hint: (None, None)
    size: (160, 120)
    pos_hint: {'center_x': .5, 'y': .6}
        text: 'Cut'
        text: 'Copy'
        text: 'Paste'


Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads