Claudiordgz
Claudiordgz

Reputation: 3049

How to bind using kivy only?

I want to create a Widget changing only the text of a label inside it, but all the ways I find how to change this are by changing it in the python code instead of reusing only Kivy objects.

So I have a widget like the following:

<AmiLabel@Label>
    color: .1, .5, .8, 1
    font_size: 16

<AmiTextInput@TextInput>
    font_size: 16

<PropertyInputForm>:
    BoxLayout:
        size: root.size
        pos: root.pos
        orientation: 'horizontal'
        AmiLabel:
            text: 'Folder Location'
            size_hint_x: .5
        AmiTextInput:
            text: 'None'
            size_hint_x: .5

<MainFormWidget>:
    BoxLayout:
        size: root.size
        pos: root.pos
        id: foo_bar
        padding: 5
        spacing: 5
        canvas:
            Color:
                rgb: (1, 1, 1)
            Rectangle:
                pos: self.pos
                size: self.size
        orientation: 'vertical'
        AmiLabel:
            height: 36
            size_hint_x: 1
            size_hint_y: None
            text: 'Project Name'
        PropertyInputForm:
            height: 36
            size_hint_x: 1
            size_hint_y: None
            # I WANT TO CHANGE THE TEXT OF THE LABEL IN HERE
        PropertyInputForm:
            height: 36
            size_hint_x: 1
            size_hint_y: None
            # I WANT TO CHANGE THE TEXT OF THE LABEL IN HERE

All I want to is change the text of the label from another widget in another level without touching the python code.

¿Is that possible?

Upvotes: 1

Views: 178

Answers (1)

inclement
inclement

Reputation: 29460

One simple way would be to add a new property to your PropertyInputForm and reference or set that.

<PropertyInputForm>:
    new_text_property: ''
    BoxLayout:
        size: root.size
        pos: root.pos
        orientation: 'horizontal'
        AmiLabel:
            text: root.new_text_property
            size_hint_x: .5
        AmiTextInput:
            text: 'None'
            size_hint_x: .5

and later

       PropertyInputForm:
            height: 36
            size_hint_x: 1
            size_hint_y: None
            new_text_property: 'whatever'

You may also need to declare new_text_property in the python class to have it be a StringProperty rather than an ObjectProperty, though even that is I think not necessary in kivy 1.8.

Upvotes: 2

Related Questions