Actually, I was testing kivy, which is I just installed and I made a simple program to test it and here is the program:-
from kivy.app import App
from kivy.uix.widget import Widget
class button(Widget):
pass
class ButtonApp(App):
def build(self):
return button()
if __name__=="__main__":
ButtonApp().run()
When I run it, I got the following error. I tried to solve it and searched on the google too many times but not getting the solution. Please help me out.
Traceback (most recent call last):
File "/root/PycharmProjects/untitled/Button.py", line 12, in <module>
ButtonApp().run()
File "/root/kivyinstall/local/lib/python2.7/site-packages/kivy/app.py", line 802, in run
root = self.build()
File "/root/PycharmProjects/untitled/Button.py", line 9, in build
return button()
File "/root/kivyinstall/local/lib/python2.7/site-packages/kivy/uix/widget.py", line 345, in __init__
Builder.apply(self, ignored_consts=self._kwargs_applied_init)
File "/root/kivyinstall/local/lib/python2.7/site-packages/kivy/lang/builder.py", line 451, in apply
self._apply_rule(widget, rule, rule, ignored_consts=ignored_consts)
File "/root/kivyinstall/local/lib/python2.7/site-packages/kivy/lang/builder.py", line 506, in _apply_rule
rule.canvas_root, rootrule)
File "/root/kivyinstall/local/lib/python2.7/site-packages/kivy/lang/builder.py", line 831, in _build_canvas
'{}: {}'.format(e.__class__.__name__, e), cause=tb)
kivy.lang.builder.BuilderException: Parser: File "/root/kivyinstall/local/lib/python2.7/site-packages/kivy/data/style.kv", line 17:
...
15: canvas:
16: Color:
>> 17: rgba: self.background_color
18: BorderImage:
19: border: self.border
...
BuilderException: Parser: File "/root/kivyinstall/local/lib/python2.7/site-packages/kivy/data/style.kv", line 17:
...
15: canvas:
16: Color:
>> 17: rgba: self.background_color
18: BorderImage:
19: border: self.border
...
AttributeError: 'button' object has no attribute 'background_color'
File "/root/kivyinstall/local/lib/python2.7/site-packages/kivy/lang/builder.py", line 249, in create_handler
return eval(value, idmap), bound_list
File "/root/kivyinstall/local/lib/python2.7/site-packages/kivy/data/style.kv", line 17, in <module>
rgba: self.background_color
File "kivy/weakproxy.pyx", line 30, in kivy.weakproxy.WeakProxy.__getattr__ (/tmp/pip-build-LU3E8I/kivy/kivy/weakproxy.c:1386)
File "/root/kivyinstall/local/lib/python2.7/site-packages/kivy/lang/builder.py", line 825, in _build_canvas
key, value, prule, idmap, True)
File "/root/kivyinstall/local/lib/python2.7/site-packages/kivy/lang/builder.py", line 254, in create_handler
cause=tb)
Process finished with exit code 1
There is already a Kivy widget called Button
. Your own button
class is conflicting with this, due to case differentiation limitations in kv language.
In general, you should CamelCase for widget class names (in line with pep8), and avoid replicating Kivy's built in class names. This will ensure that everything works correctly.