Kivy es una herramienta GUI independiente de la plataforma en Python. Como se puede ejecutar en Android, IOS, Linux y Windows, etc. B谩sicamente se usa para desarrollar la aplicaci贸n de Android, pero eso no significa que no se pueda usar en aplicaciones de escritorio.
Burbuja:
El widget Bubble es una forma de men煤 o una peque帽a ventana emergente donde las opciones del men煤 se apilan vertical u horizontalmente. La burbuja contiene una flecha que apunta en la direcci贸n que elija.
Para elegir la direcci贸n en la que se usan las puntas de flecha:
Burbuja(arrow_pos=’top_mid’)
La orientaci贸n de la burbuja es horizontal por defecto, pero puede cambiarla con el comando:
orientaci贸n = ‘vertical’
Para agregar elementos a la burbuja:
bubble = Bubble(orientaci贸n = ‘vertical’)
bubble.add_widget(your_widget_instance)
Para eliminar elementos:
bubble.remove_widget(widget)
o
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
# Implementaci贸n del Enfoque:
# c贸digo .py:
# 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()
Archivo .kv:
# .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'
Producci贸n:
Publicaci贸n traducida autom谩ticamente
Art铆culo escrito por YashKhandelwal8 y traducido por Barcelona Geeks. The original can be accessed here. Licence: CCBY-SA