adding buttons and changing text all in python.

14 views
Skip to first unread message

ewanmc...@hotmail.com

unread,
Oct 20, 2016, 9:52:19 AM10/20/16
to Kivy users support
I am not able to change the text property of dynamically created buttons. But I am not sure I am even taking the best opproach, hopefully someone will be able to educate me.

In kv I have a load of buttons with uniqueids. Then in python I receive by socket connection a dictionary mapping the uniqueids to text to display on the buttons.
This works well, can change its text by referring to it's "id" tag in python, simple.

def ReceivedData(uniqueid,newtext)
    self.id["uniqueid"].text=newtext

But Now, instead of manually creating the buttons in kv, I want receive the list of unique ids in python, then create them and later alter the text as before.
But it doesn't work. The buttons are created but I have no reference to them.
From what i have read i think it is because the ids are only generated when it loads the kv. Every evening I have been trying different things to achieve this but just get lost and confused :(

ewanmc...@hotmail.com

unread,
Oct 20, 2016, 10:33:08 AM10/20/16
to Kivy users support
I forgot to say if I inspect the properties of the dynamically created buttons using the awesome kivy console I can see that the id property has correctly been added to each button, I just don't know how to reference it from the python code.

ZenCODE

unread,
Oct 20, 2016, 5:02:13 PM10/20/16
to Kivy users support
Then just store references to them via a dict.

self.my_buttons = {'one': Button(text="One"), 'two': Button(text='Two')}

Post the code if you can't see how to do this.

ewanmc...@hotmail.com

unread,
Oct 21, 2016, 8:22:39 AM10/21/16
to Kivy users support
Brilliant, works a treat.
Thank you very much.

ZenCODE

unread,
Oct 21, 2016, 11:22:00 AM10/21/16
to Kivy users support
Yay. It's a pleasure :-)
Reply all
Reply to author
Forward
0 new messages