The Python file looks like this (main.py):
from kivy.app import App from kivy.uix.widget import Widget from kivy.uix.tabbedpanel import TabbedPanel from kivy.uix.floatlayout import FloatLayout from kivy.uix.screenmanager import ScreenManager, Screen from kivy.graphics.context_instructions import Color from kivy.uix.label import Label from kivy.lang.builder import Builder class sivaLoginScreen(Screen): def __init__(self,**kwargs): super(sivaLoginScreen,self).__init__(**kwargs) with self.canvas.before: Color(253,253,152,1) class sivaTabbedScreen(Screen): pass class sivaScreenManager(ScreenManager): pass # Tell Kivy to directly load a file. If this file defines a root widget, it will be returned by the method. root_widget = Builder.load_file('siva.kv') class sivaApp(App): def build(self): # Initialize root widget return root_widget if __name__ == '__main__': # Run application sivaApp().run()
The kv file looks something like this (siva.kv):sivaScreenManager: sivaLoginScreen: <sivaLoginScreen>: name='login_screen' FloatLayout: Label: id: login_label pos: 100, 100 text: 'S.I.V.A'
When I run the app withpython3 main.py
I get the following error:Traceback (most recent call last): File "main.py", line 30, in <module> root_widget = Builder.load_file('siva.kv') File "/usr/lib/python3/dist-packages/kivy/lang/builder.py", line 301, in load_file return self.load_string(data, **kwargs) File "/usr/lib/python3/dist-packages/kivy/lang/builder.py", line 368, in load_string parser = Parser(content=string, filename=fn) File "/usr/lib/python3/dist-packages/kivy/lang/parser.py", line 401, in __init__ self.parse(content) File "/usr/lib/python3/dist-packages/kivy/lang/parser.py", line 510, in parse objects, remaining_lines = self.parse_level(0, lines) File "/usr/lib/python3/dist-packages/kivy/lang/parser.py", line 624, in parse_level 'Invalid property name') kivy.lang.parser.ParserException: Parser: File "/home/shoumik/code/siva/siva.kv", line 6: ... 4: 5:<sivaLoginScreen>: >> 6: name='login_screen' 7: FloatLayout: 8: Label: ... Invalid property name
Can you please help me understand where I am going wrong? In the official crash course videos, the name attribute was not defined as a property in the main.py file.
Thanks in advance!!
Replace: name='login_screen'
With: name: ‘login_screen’
--
You received this message because you are subscribed to the Google Groups "Kivy users support" group.
To unsubscribe from this group and stop receiving emails from it, send an email to kivy-users+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/9e389c16-9218-42fa-b96d-0fe4ded13e69%40googlegroups.com.
To unsubscribe from this group and stop receiving emails from it, send an email to kivy-...@googlegroups.com.
I combined the kv and the python file into one to make things a little easier.
You had set the color, but did not provide any direction to draw anything. I move the canvas instructions to kv, and added the Rectangle command, setting the size and position to match the size and pos of the screen.
I moved the name of the screen to the instance, rather than the Screen definition. You can put them in either place, but I find it is easier to manage when all of the names are together under the screen manager.
I changed the names of your classes to use CamelCase or CapWords case. This is a convention for Python, and occasionally Kivy requires things this way.
See: https://pep8.org/#class-names
I also put a black outline on your text, the white text on a yellow background was difficult to read.
from kivy.app import App
from kivy.uix.widget import Widget
from kivy.uix.tabbedpanel import TabbedPanel
from kivy.uix.floatlayout import FloatLayout
from kivy.uix.screenmanager import ScreenManager, Screen
# from kivy.graphics.context_instructions import Color # removed, put your color commands in kv
from kivy.uix.label import Label
from kivy.lang.builder import
Builder
kv = """
SivaScreenManager: # Use CamelCase for Classes
SivaLoginScreen:
name: 'login_screen'
<SivaLoginScreen>:
canvas:
Color:
rgba: 253/255, 253/255, 152/255, 1
Rectangle:
size: self.size
pos: self.pos
FloatLayout:
Label:
id: login_label
pos: 100, 100
text: 'S.I.V.A'
font_size: 40
outline_color: 0, 0, 0 # added a black outline to the chars, white is hard to see on the yellow background
outline_width: 1
"""
class SivaLoginScreen(Screen):
# def __init__(self, **kwargs):
# super(sivaLoginScreen, self).__init__(**kwargs)
# with self.canvas.before:
# Color(253, 253, 152, 1)
pass
class SivaTabbedScreen(Screen):
pass
class SivaScreenManager(ScreenManager):
pass
# Tell Kivy to directly load a file. If this file defines a root widget, it will be returned by the method.
#root_widget = Builder.load_file('siva.kv')
class SivaApp(App):
def build(self):
# Initialize root widget
return Builder.load_string(kv)
if __name__ == '__main__':
# Run application
SivaApp().run()
To unsubscribe from this group and stop receiving emails from it, send an email to kivy-users+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/46a39abe-f8c5-40f1-808d-3eb71faf95d7%40googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/46a39abe-f8c5-40f1-808d-3eb71faf95d7%40googlegroups.com.
Glad to hear it helped you! Enjoy the journey.
To unsubscribe from this group and stop receiving emails from it, send an email to kivy-users+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/51386162-245a-4995-b6bd-5c3c38e83a68%40googlegroups.com.