Python | Bubble in kivy
Last Updated :
06 Feb, 2020
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:
import kivy
from kivy.app import App
kivy.require( '1.9.0' )
from kivy.uix.floatlayout import FloatLayout
from kivy.uix.button import Button
from kivy.uix.bubble import Bubble
from kivy.properties import ObjectProperty
class Cut_copy_paste(Bubble):
pass
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()
def show_bubble( self , * l):
self .add_widget( self .bubb)
class BubbleApp(App):
def build( self ):
return BubbleDemo()
if __name__ = = '__main__' :
BubbleApp().run()
|
.kv file:
<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:
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...