Building dynamic variables for menus in Python

819 Views Asked by At

I'm using an excellent menu structure function from Github which is powering a small LCD. The menus contain top (parent) elements and sub elements, and I want to build the sub-elements dynamically. Currently they're static and work like this:

top5 = menu.topElement("< top5         >", "STRING", "        v")
sub25 = menu.subElement("Bus>Times", "STRING", "this is a really long scroll string")

menu.addSubElement(top5, sub25)

I have another function which will output the text of the required sub-element menus. What I can't fathom is how to generate sub26, sub27 etc. dynamically (there could be 1, or 7, or any number really), and each of them will contain different content. I am absolutely stuck!

I'm trying to work on a dict but my brain can't understand how this will output a dynamic variable name (incremental), with dynamic content attributed to it (where xx is dynamic below)

subXX = menu.subElement("Top 5> More", "STRING", "XX")
1

There are 1 best solutions below

1
On

why not to use lists?

sub[i] = menu.subElement("text", "STRING", "XX")

where i is any number.