Access parent size options in kivy widgets

I am learning Kivy and would like to center the object inside the parent object. I know that I can access the own properties of an object with the self keyword in kv, but is there a shortcut to access the properties of the parent widget, say, size and position? Both root.size and parent.size do not work for me.

+7
python kivy
source share
1 answer

The widget stores the link to the parent in self.parent . That way you can just self.parent.size or self.parent.pos or something else.

Depending on what you are doing, it may be necessary or useful to make sure that you first check to see if self.parent is None so that your code does not depend on widgets without a parent.

+8
source share

All Articles