Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Accessing the parent object's size parameters in kivy widgets

Tags:

python

kivy

Im learning Kivy and would like to center an object inside of a parent object. I know I can access an object's own properties with the self keyword in the kv language, but is there a shortcut for accessing a parent widget's, say, size and position properties? Both root.size and parent.size are failing for me.

like image 864
Mittenchops Avatar asked Dec 09 '13 00:12

Mittenchops


Video Answer


1 Answers

A widget keeps a reference to its parent in self.parent. So you can just so self.parent.size or self.parent.pos or whatever.

Depending on what you're doing, it may be necessary or useful to make sure you check if self.parent is None first, so that your code doesn't fail for widgets with no parent.

like image 139
inclement Avatar answered Sep 28 '22 09:09

inclement