Ejemplo de código que nos permite añadir a un widget kv desde Python.
from kivy.app import App from kivy.core.window import Window from kivy.uix.boxlayout import BoxLayout from kivy.uix.button import Button # etiquetas class Tag(Button): pass class RootWidget(BoxLayout): def btn_clk(self): self.ids.cuerpo.add_widget(Tag()) pass # Clase principal class KanbanApp(App): def build(self): return RootWidget() # crea la clase root kanban=KanbanApp() # Inicia la ejecución del software if __name__ == '__main__': kanban.run()
# Interfaz principal #:kivy 1.0.9 #:import utils kivy.utils <Tag@Button> id:tagButton texto:self.texto font_size: self.height * 0.15 text_size:self.width, None size_hint: None, None pos_hint:{"left":1,"top":1} #height: self.parent.height*0.2 #width:self.parent.width*0.3 background_color:utils.get_color_from_hex('#FF1800') <RootWidget>: orientation:'vertical' canvas: Color: rgba: 1, 1, 1, 1 Rectangle: #woohoo!!! size: self.size pos: self.pos # Cabecera aplicación BoxLayout: id:logoApp size_hint_y:None size_hint_y:.2 # logo quoti Image: source:'RECURSOS/kanbanLogo.png' pos_hint:{"left":1,"top":1} size_hint:None, None height:self.parent.height Label: id:texto text:"Hospital Demo Quoti" font_size: self.height * 0.2 #text_size:self.width, None color: 0,0,0,1 Image: source:'RECURSOS/logoQuoti.png' pos_hint:{"right":1,"top":1} size_hint:None, None height:self.parent.height # representa los tags pedidos StackLayout: id: cuerpo orientation:'lr-tb' padding:dp(10) BoxLayout: orientation:"horizontal" size_hint_y:None size_hint_y:.2 Button: text:"TAGS" on_press: root.btn_clk() Image: source:"RECURSOS/tag.png" height: self.parent.height/2 center_y: self.parent.center_y center_x: self.parent.center_x-(self.parent.width/4) allow_stretch:True Button: text:"BUSCAR" Image: source:"RECURSOS/find.png" height: self.parent.height/2 center_y: self.parent.center_y center_x: self.parent.center_x-(self.parent.width/4) allow_stretch:True Button: text:"Pedidos" Image: source:"RECURSOS/pedidos.png" height: self.parent.height/2 center_y: self.parent.center_y center_x: self.parent.center_x-(self.parent.width/4) allow_stretch:True