Inside a kv file, root always refers to a parent with angle brackets. There can therefore be multiple roots which you can refer to in a kv file, depending on where you are in the file.
# Root here refers to the parent class in angle brackets
<SomeClass>:
BoxLayout:
Label:
text: root.label_text
# and further down in the same kv file, this other
# class is also a root.. here root refers to
# this class
<SomeOtherClass/Widget/LayoutEtc>:
BoxLayout:
Label:
text: root.label_text
In a python file then, these classes could be represented like so:
class SomeClass:
label_text = StringProperty("I'm a label")
def __init__(**kwargs):
super(SomeClass, self).__init__(**kwargs)
b = BoxLayout()
l = Label(text=self.label_text)
b.add_widget(l)
self.add_widget(b)
# now we're set up like the first class in the above kv file
Now look above and compare how the kv file assigned the text to the label, and how it's done in the python file above. In kv it was root.label_text
, but above, the class uses self
. As in, text=self.label_text
. It's also used when adding the boxlayout, self.add_widget(b)
. self
is a way of referring to the current instance of the class.
That's how you basically refer to what would be 'root' in the kv file, but in the python file.
If you don't know why self
is used, then I advise learning about classes in python, as that's where the explanation to that lies.