Table of contents
1.
Introduction
2.
About kivy
3.
Bubble Widget
4.
Customisation of Bubble Widget
4.1.
Implementation
4.2.
Output
5.
FAQs
5.1.
What is Kivy?
5.2.
What is the Bubble widget in Kivy?
5.3.
What is the widget in Kivy?
5.4.
What is the root of Kivy?
6.
Conclusion
Last Updated: Mar 27, 2024
Easy

Bubble in Kivy

Author Aniket Majhi
1 upvote
Career growth poll
Do you think IIT Guwahati certified course can help you in your career?

Introduction

Welcome readers! We hope you are doing well.

This blog is going to be interesting for you. Nowadays, Python has become one of the most important tools in developing different applications from a programmer's perspective. It has a lot of library support. If you want to impact the development field in Python, you need to learn more about different libraries in Python.

If you want to learn more about python, you can refer to the link Basics of Python.

In this blog, we will be discussing the Bubble in the Kivy library in Python. We will cover every aspect of the Bubble Widget.

This blog will help enhance your knowledge about the Kivy library in Python and help you stand out from the crowd.

About kivy

Kivy is an open-source platform-independent GUI development python library for developing innovativemulti-touch UI applications. It can run on WindowsGNU/LinuxAndroidiOS etc.

Kivy is mainly used to develop Android Applications. It is also used in developing the Desktop Applications as well. 

Bubble Widget

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?

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 PythonKivy 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!

Live masterclass