0
votes

Following code from here I've created a simple button with rounded corners like so:

<RoundedButton@Button>:
background_color: 0,0,1,0  
canvas.before:
    Color:
        rgba: (.216,.118,.329,1) if self.state=='normal' else (0,.7,.7,1)  
    RoundedRectangle:
        pos: self.pos
        size: self.size
        radius: [10,]
RelativeLayout:     
    pos: self.parent.pos
    size: self.parent.size
    Label:
        text: 'Button Text'
        font_size: 20
        pos_hint: {'center_x': 0.5,'center_y':0.5}
        id: _labeltext

When I use this button in my kv code, I'd like a simple way to change the text of the button, which I'd like to do using the id value '_labeltext'. This seems like it should be simple but I've not been able to find how to change this in the KV code rather than in python (as a response to an action). I'd just like to reuse my button design multiple times with different text. For example (I know this doesn't work):

RoundedButton:
self.ids._labeltext.text: 'New Button Text'

Thanks

P.S. can't get indentation correct in the editor, apologies

1
The indentation in your kv is incorrect. Please adjust your posted kv to reflect the actual indentation used. Is the RelativeLayout part of the RoundedButton ? - John Anderson
Yes, I had really issues with this in the text editor. I pasted the code with indentations complete but this didn't copy over. I wasn't able to then add additional tabs to correct it. Do you know how I do this? - Wiredchop

1 Answers

0
votes

You can adjust the text of the RoundedButton just as you would any other Button:

RoundedButton:
    text: 'Hello'