I don’t understand how to do assignment checking to a variable, as it is done in Kivy. I know how this is done for class properties, and it looks like this
#!/usr/bin/python3.6
class Foo:
var = property()
def __init__(self):
self._var = 0
@var.setter
def var(self, value):
self._var = value
# code setter
pass
@var.getter
def var(self):
# code getter
print('Getter method')
return self._var
a = Foo()
a.var = 5
print(a.var)
# Getter method
# 5
In Kivy can do:
class LabelBase(Label):
msg = StringProperty('t')
def __init__(self, **kwargs):
super(LabelBase, self).__init__(**kwargs)
self.msg = 5
I take
Traceback (most recent call last):
File "/home/Python/Prj/View/Main.py", line 83, in <module>
Start().build()
File "/home/Python/Prj/View/Main.py", line 73, in build
GUI().run()
File "/usr/lib/python3/dist-packages/kivy/app.py", line 800, in run
root = self.build()
File "/home/Python/Prj/View/Main.py", line 65, in build
main_window = MainFrame()
File "/home/Python/Prj/View/Main.py", line 52, in __init__
self.label = LabelBase(text='test')
File "/home/Python/Prj/View/Main.py", line 16, in __init__
self.msg = 5
File "kivy/properties.pyx", line 483, in
kivy.properties.Property.__set__
File "kivy/properties.pyx", line 521, in kivy.properties.Property.set
File "kivy/properties.pyx", line 512, in kivy.properties.Property.set
File "kivy/properties.pyx", line 678, in
kivy.properties.StringProperty.check
ValueError: LabelBase.msg accept only str
Renamed the question because it did not correspond to what was happening