Understanding difference between self.x, self.width and root.width

328 views
Skip to first unread message

Shoumik Das

unread,
Apr 29, 2020, 7:13:25 AM4/29/20
to Kivy users support
Hi. I have built a simple screen to understand the concepts behind self.x, self.width and root.width. My intention is to place a text label at the center of my app screen. This is my kv file:

This one works fine.

<SivaTabbedScreen>:
    name: 'tabbed_screen'
    FloatLayout:
        size: root.width, root.height
        Label:
            pos: self.x*0.5, self.y*0.5
            text: 'SECOND SCREEN'
            font_size: '50sp'

This one does not work as intended.

<SivaTabbedScreen>:
    name: 'tabbed_screen'
    FloatLayout:
        size: root.width, root.height
        Label:
            pos: self.width*0.5, self.height*0.5
            text: 'SECOND SCREEN'
            font_size: '50sp'

Can you please help me understand the different values of self.x, self.width and root.width in the above examples?

Elliot Garbus

unread,
Apr 29, 2020, 11:24:23 AM4/29/20
to kivy-...@googlegroups.com

Read about x, y height and width in: https://kivy.org/doc/stable/api-kivy.uix.widget.html?highlight=widget#module-kivy.uix.widget

 

In short:

self.x and self.y are the position of the lower left corner of the widget.

self.height and self.width are the height and width of the widget.

 

Read about root: https://kivy.org/doc/stable/api-kivy.lang.html?highlight=lang#value-expressions-on-property-expressions-ids-and-reserved-keywords

root.width is the width of the SivaTabbedScreen.

 

You can print root, print(root) or print(self) to see what it is.

--
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.
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/7faf5bb4-9cc4-4652-8b86-975d9167a102%40googlegroups.com.

 

Shoumik Das

unread,
Apr 29, 2020, 11:40:09 AM4/29/20
to Kivy users support
Thank you for helping me understand.

Elliot Garbus

unread,
Apr 29, 2020, 11:42:19 AM4/29/20
to kivy-...@googlegroups.com

😊

 

From: Shoumik Das
Sent: Wednesday, April 29, 2020 8:40 AM
To: Kivy users support

--

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.

Reply all
Reply to author
Forward
0 new messages