Setting a button's position

Hi to all,
Simple question here, how do I position a button whose text is not hard-coded, but is determined by user input?
For example:

userText=self.storedUserRecipes[0]
radioButton=DirectRadioButton(text = userText, scale=0.07, pos=(0.1,0,0.1))

Here, the list “self.storedUserRecipes” is a list of strings that the user input themselves. So the strings are of varying length and initiating their position to “0.1” x-wise doesn’t make them all start at the same place onscreen. Depending on the length of the string, some start further to the left or to the right than others.
I’ve tried this too:

...
radioButton.setPos(render2d,0.1,0,0.1)
...

to no avail. So how would I make them all start at the same position visually on the screen despite them having texts whose strings are of varying lengths?

Thanks in advance.

Have you tried left-aligning them? To do so, add another parameter to the construction of your DirectRadioButton: “text_align = TextNode.ALeft”. Note that this may call for importing “TextNode”, if you’re not already doing so.

(You can also right-align them similarly, if that’s preferable, I believe.

Thank you very much! That did the trick.

My pleasure! I’m glad that it helped! :slight_smile: