Can you guys have a look at my python/kivy code?
main.py (copied from video tutorial):
from kivy.app import App
from kivy.uix.widget import Widget
class MainWidget(Widget):
pass
class TheLabApp(App):
pass
TheLabApp().run()
thelab.kv:
#:kivy ! 2.1.0
MainWidget:
<MainWidget>:
Button:
text: "Hello"
size: "200dp", "100dp"
pos: "100dp", "200dp"
Running this code ends up with diffrent results. Sometimes it compiles returning empty window, sometimes it ends up with this (or similar) errors:
Traceback (most recent call last):
File "c:\Users\klaud\Documents\Studia\A Python\test\main.py", line 10, in <module>
TheLabApp().run()
File "C:\Users\klaud\AppData\Roaming\Python\Python310\site-packages\kivy\app.py", line 954, in run
self._run_prepare()
File "C:\Users\klaud\AppData\Roaming\Python\Python310\site-packages\kivy\app.py", line 923, in _run_prepare
self.load_kv(filename=self.kv_file)
File "C:\Users\klaud\AppData\Roaming\Python\Python310\site-packages\kivy\app.py", line 696, in load_kv
root = Builder.load_file(rfilename)
File "C:\Users\klaud\AppData\Roaming\Python\Python310\site-packages\kivy\lang\builder.py", line 305, in load_file
return self.load_string(data, **kwargs)
File "C:\Users\klaud\AppData\Roaming\Python\Python310\site-packages\kivy\lang\builder.py", line 372, in load_string
parser = Parser(content=string, filename=fn)
File "C:\Users\klaud\AppData\Roaming\Python\Python310\site-packages\kivy\lang\parser.py", line 483, in __init__
self.parse(content)
File "C:\Users\klaud\AppData\Roaming\Python\Python310\site-packages\kivy\lang\parser.py", line 590, in parse
self.execute_directives()
File "C:\Users\klaud\AppData\Roaming\Python\Python310\site-packages\kivy\lang\parser.py", line 569, in execute_directives
raise ParserException(self, ln, 'Unknown directive')
kivy.lang.parser.ParserException: Parser: File "c:\Users\klaud\Documents\Studia\A Python\test\thelab.kv", line 1:
...
>> 1:#:kivy
2:
3:MainWidget:
...
Unknown directive
Code is copied from yt, where it worked just fine. Have you got any ideas?
According to the documentation, the first line of a .kv
file should be
#:kivy `1.0`
where 1.0
is the lowest version you support, or simply the version you're currently using. I have version 2.1.0, so my header line is
#:kivy 2.1.0
without the !
. That worked fine for me.
Completely removing the header also worked.