Search code examples
python-3.xkivywidget

how change kivy's widget's settings using python script?


how could i change settings of a widget declared in a kivy file using its own python class? example:

kv file:

<Button>:
Button:
    name:'btn'
    text:'yes'
    on_press:doet()

py file:

class Button(self):
    def doet():
        btn.text='nope'

Solution

  • You can solve this by setting an ID to the button. All you got to do is add id: "btn" to your .kv file and you could access this through self.ids.btn.text in your .py file. So it must look like this:

    .kv

    <Button>
        Button:
            id:'btn'
            text:'yes'
            on_press: root.doet()
    

    .py

    class Button:
        def doet(self):
            self.ids.btn.text='nope'