Website | Source | Docs

Uses a "design language" (Kv Design Language) to separate code from layout:

#:kivy 1.0

    label_wid: my_custom_label

        orientation: 'vertical'
        padding: 20

            text: 'My controller info is: ' +
            on_press: root.do_action()

            id: my_custom_label
            text: 'My label before button press'

... matched up with code...

import kivy

from kivy.uix.floatlayout import FloatLayout
from import App
from import ObjectProperty, StringProperty

class Controller(FloatLayout):
    '''Create a controller that receives a custom widget from the kv lang file.

    Add an action to be called from the kv lang file.
    label_wid = ObjectProperty()
    info = StringProperty()

    def do_action(self):
        self.label_wid.text = 'My label after button press' = 'New info text'

class ControllerApp(App):

    def build(self):
        return Controller(info='Hello world')

if __name__ == '__main__':

Tags: presentation   python   android   ios   macos   windows  

Last modified 30 May 2024