Bubble Widget
A Bubble widget is a form of a menu or small popup where the menu options are stacked either vertically or horizontally.
The Bubble contains an arrow pointing in the direction you choose.
Customisation of Bubble Widget
- The direction in which the arrow points can be chosen using:
Bubble(arrow_pos = 'top_mid')

You can also try this code with Online Python Compiler
Run Code
- By default, the widgets added to the bubble are oriented horizontally. It can be changed to vertically using:
orientation = 'vertical'

You can also try this code with Online Python Compiler
Run Code
- You can add items to the bubble using:
bubble = Bubble()
bubble.add_widget(your_widget_instance)

You can also try this code with Online Python Compiler
Run Code
- You can remove items from the bubble using:
bubble = Bubble()
bubble.remove_widget(widget)
#or
bubble.clear_widgets()

You can also try this code with Online Python Compiler
Run Code
- You can access the children using:
bubble = Bubble()
bubble.content.children

You can also try this code with Online Python Compiler
Run Code
Implementation
# importing kivy module
import kivy
from kivy.app import App
# The float layout widget
from kivy.uix.floatlayout import FloatLayout
# The button widget
from kivy.uix.button import Button
# The Bubble widget
from kivy.uix.bubble import Bubble
from kivy.uix.bubble import BubbleButton
# Create the BubbleApp class
class BubbleApp(App):
def build(self):
# creating the float layout
self.root = FloatLayout()
# creating button to the layout
button = Button(text='Click here to show bubble',on_press=self.show_bubble)
# adding button
self.root.add_widget(button)
return self.root
# Defining the function to show the bubble
def show_bubble(self, obj):
# Creating bubble
bubble = Bubble(size_hint=(None, None), size=(160, 120), pos_hint={'center_x': .5, 'y': .5})
# creating bubble buttons
button1 = BubbleButton(text = "one")
button2 = BubbleButton(text = "two")
button3 = BubbleButton(text = "three")
# adding buttons to the bubble
bubble.add_widget(button1)
bubble.add_widget(button2)
bubble.add_widget(button3)
# adding bubble
self.root.add_widget(bubble)
# run the App
if __name__ == '__main__':
BubbleApp().run()

You can also try this code with Online Python Compiler
Run Code
Output

FAQs
What is Kivy?
Kivy is an open-source platform-independent GUI development python library for developing applications.
What is the Bubble widget in Kivy?
A Bubble widget is a form of a menu or small popup where the menu options are stacked either vertically or horizontally.
What is the widget in Kivy?
The widget in Kivy is the base building block of the GUI interface.
What is the root of Kivy?
The root inside a kv file refers to the parent with the angular brackets.
Conclusion
In this article, we have extensively discussed the Bubble in Kivy.
- We started with the basic introduction.
- We discussed the Kivy.
- We looked at what a Bubble is in Kivy.
-
We showed the implementation of the Bubble in Kivy.
We hope that this blog has helped you enhance your knowledge regarding Bubble in Kivy. If you would like to learn more, check out our articles on Open Source Python Libraries and Application Development in Python, Kivy Float Layout in Python, and Popular Python Libraries. Do upvote our blog to help other ninjas grow.
Head over to our practice platform Coding Ninjas Studio to practice top problems, attempt mock tests, read interview experiences, follow our guided paths, and crack product based companies Interview Bundle.
Happy Reading!