Direct Label : justified position [closed]


I am creating a properties window.
I create some directLabel or DirectInput to show properties, one under the other.
But even I specify the same posX, depending of the size of the text, the label appears at posX-0.05, posX-0.1, …
How can avoid, the change of the size of the box containing the text, and that the label are not aligned?

Specify frameSize = (-.5, 10, -0.5, 1.5), or whatever size makes sense for your labels. The parameters are left, right, bottom, top.

After several months of absence, I come back on this topic.

In fact, I used frameSize on my declaration, but it seems that the frame goes on the left when I put text.

Let see the code

myFirstLabel=DirectLabel(parent=self.background,text="Nom :" + item.getName(),pos=(-0.15,0,-0.05),scale=.05,text_bg=(0.1,0.1,0.1,1),text_fg=(1,1,1,1),frameSize=(-1,10,-0.3,1.1),frameColor=(0.1,0.1,0.1,1)))
    mySecondLabel=DirectLabel(parent=self.background,text="Prix a la vente :" + str(item.getSell()),pos=(-0.15,0,-0.25),scale=.05,text_bg=(0.1,0.1,0.1,1),text_fg=(1,1,1,1),frameSize=(-1,10,-0.3,1.1),frameColor=(0.1,0.1,0.1,1)))

The second Label is decaled on the left, because I think, the text is longer.

How can I avoid this?


Where you you want it to appear? Vary the frameSize parameters to place the frame in the right place around the text. Or, alternatively, vary the text_pos parameter to place the text in the right place within the frame.

You’ve also got two different background cards: the one created by frameSize (pass relief = None to disable this one) and the one created to match the text (don’t set text_bg to disable this one).


The problem is that the text inside the directLabel is not always the same. The text shown depending on the item on which user click.

So I can’t place statically the directlabel, and that is why I a am in Anger with directLabel. They grow up, and move left depending of the size of the text.

I hope I don’t need to get the length of the text and provide new position depending of the delta of length between first and second label…

I don’t understand what you mean by “move left”. Maybe you want a different alignment, e.g. text_align = TextNode.ALeft?


nono the directlabel is one step left from the previous directlabel.

Like two box, one at x=0 for the first, and the second x=-5, but on the right of the box, first is at 20, and the second at 20 two.
The first box has now a width of 10, and the second 15.

Right, that sounds like text alignment. The default alignment is centered, which means that the x parameter you specify is actually the x parameter of the center of the box. If you specify text_align = TextNode.ALeft, then the x parameter will indicate the left edge of the box, and if the text is wider it will not change the left edge, only the right edge.


Halleluia, it is exactly what I meant. Thank you!