Friday, December 27, 2024
Google search engine
HomeLanguagesPython | Bubble in kivy

Python | Bubble in kivy

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:

Bubble(arrow_pos=’top_mid’)

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’)
bubble.add_widget(your_widget_instance)

To remove items:

bubble.remove_widget(widget)
or
bubble.clear_widgets()

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 kivy.app import App 
     
# this restrict the kivy version i.e  
# below this kivy version you cannot  
# use the app or software  
kivy.require('1.9.0'
  
# 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 kivy.properties import ObjectProperty
   
  
# Create the Bubble class
# on which the .kv file is
class Cut_copy_paste(Bubble):
    pass
  
# 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.add_widget(self.but_bubble)
        self.bubb = Cut_copy_paste()
  
    # Defining the function to show the bubble
    def show_bubble(self, *l):
        self.add_widget(self.bubb)
              
# Create the App class
class BubbleApp(App):
    def build(self):
        return BubbleDemo()
  
# run the App
if __name__ == '__main__':
    BubbleApp().run()


.kv file:




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


Output:

Dominic Rubhabha-Wardslaus
Dominic Rubhabha-Wardslaushttp://wardslaus.com
infosec,malicious & dos attacks generator, boot rom exploit philanthropist , wild hacker , game developer,
RELATED ARTICLES

Most Popular

Recent Comments