Position a label relative to it's parents button

330 views
Skip to first unread message

Sean Duane

unread,
Mar 6, 2013, 1:10:55 AM3/6/13
to kivy-...@googlegroups.com

I have a widget, which has a button, which has text.

I'd like to place that text to the right of the button, maybe even go as crazy as to italisize that text, and have it be placed over as far as the buttons width

Here's what I have now:
<MyWidget>:
    Button:
        pos_hint: {'center_x': .5, 'center_y': .95}
        Label:
            text: "Hello!"
            pos_x: root.x + 20

Unfortunatley, the text just gets placed at the bottom left of the screen. What is the proper way to position the label?

krister viirsaar

unread,
Mar 6, 2013, 2:59:49 AM3/6/13
to kivy-...@googlegroups.com
interesting the Label should spawn at all.
For positioning see the different layout types http://kivy.org/docs/api-kivy.uix.layout.html then position the layout properly, and button/label will follow (unless it's floatLayout)
it's not uncommon to have 3 layouts in eachother just to have a button and text next to eachother.

krister viirsaar

unread,
Mar 6, 2013, 3:05:42 AM3/6/13
to kivy-...@googlegroups.com
so this would put text next to the button:

BoxLayout:
   
Button
   
Label

and you can set the size of boxlayout

com...@motaj.com

unread,
Mar 6, 2013, 5:15:39 AM3/6/13
to kivy-...@googlegroups.com
I think he's referring to halign of the button's text

<MyWidget>:
    Button:
        text: "[i]Hello![/i]"
        text_size: self.size
        halign:'right'
        markup: True

Gabriel Pettier

unread,
Mar 6, 2013, 6:25:13 AM3/6/13
to kivy-...@googlegroups.com
Hi

where did you get that `pos_x` from? it should be `x`.

then if the MyWidget instance is correctly positioned in a layout, the
text will follow. (you likely want to put "y: root.y" or something,
too.)
> --
> You received this message because you are subscribed to the Google Groups "Kivy users support" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to kivy-users+...@googlegroups.com.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>

Sean Duane

unread,
Mar 6, 2013, 10:27:49 AM3/6/13
to kivy-...@googlegroups.com
I didn't realize that you could align a buttons text, or that you had to thrown button/labels into a layout. Thanks much for the help!
Reply all
Reply to author
Forward
0 new messages