Reputation: 171
While trying to run a sample kivy application, i m facing the above error.
here is the python code:
main.py.
from kivy.app import App
from kivy.uix.boxlayout import BoxLayout
from kivy.uix.screenmanager import Screen, ScreenManager, FadeTransition
class MyScreenManager(ScreenManager):
pass
class MainScreen(Screen):
pass
class MailScreen(Screen):
pass
class ProjectScreen(Screen):
pass
class IntroScreen(Screen):
pass
class GsaMain(BoxLayout):
pass
class GsamApp(App):
def build(self):
return MyScreenManager()
GsamApp().run()
the kivy file named gsam.kv
MyScreenManager:
IntroScreen:
MainScreen:
PrjcScreen:
MailScreen:
ChatScreen:
<IntroScreen>:
name: 'introscreen'
BoxLayout:
Label:
text: 'Welcome to GSAM'
font_size: 35
BoxLayout:
Label:
text: "Login"
TextInput:
id: login
text: "Login"
Button:
text: "Connect"
on_release: root.current = 'mainpage'
BoxLayout:
Button:
text: 'Project Page'
font_size: 25
on_release: app.root.current = 'main'
<MainScreen>:
name: 'main'
BoxLayout:
Label:
text: 'Your GSAM Portal'
font_size: 35
BoxLayout:
Button:
text: 'Check Mails'
font_size: 25
on_release: app.root.current = 'mailscreen'
canvas:
color: rgba: 1,0,0,1
Rectangle:
size: 50, 50
Label: "Post Projects"
id: projct
Rectangle:
size: 50, 50
Label: "Messages"
id: msgs
<MailScreen>:
name: 'mailscreen'
BoxLayout:
Label:
text: 'GSAM Mail'
font_size: 35
BoxLayout:
Button:
text: 'Chat'
font_size: 25
on_release: app.root.current = 'chat'
<ChatScreen>:
name: 'chatscreen'
BoxLayout:
Label:
text: 'Chat with your Colleagues'
font_size: 35
BoxLayout:
Button:
text: 'Home'
font_size: 25
on_release: app.root.current = 'main'
<PrjcScreen>:
name: 'prjcscreen'
BoxLayout:
Label:
text: 'Community Projects'
font_size: 35
BoxLayout:
Button:
text: 'community Projects'
font_size: 25
on_release: app.root.current = 'main'
GridLayout:
cols: 2
rows: 4
padding: 5
spacing: 5
Label:
text: "Project Title"
TextInput:
id: ptitle
Label:
text: "Project Description"
TextInput:
id: pdescr
I can't figure out what is the traceback pointing to.
Traceback (most recent call last):
File "main.py", line 28, in <module>
GsamApp().run()
File "/home/afidegnum/gsam/local/lib/python2.7/site-packages/kivy/app.py", line 797, in run
self.load_kv(filename=self.kv_file)
File "/home/afidegnum/gsam/local/lib/python2.7/site-packages/kivy/app.py", line 594, in load_kv
root = Builder.load_file(rfilename)
File "/home/afidegnum/gsam/local/lib/python2.7/site-packages/kivy/lang.py", line 1749, in load_file
return self.load_string(data, **kwargs)
File "/home/afidegnum/gsam/local/lib/python2.7/site-packages/kivy/lang.py", line 1796, in load_string
parser = Parser(content=string, filename=fn)
File "/home/afidegnum/gsam/local/lib/python2.7/site-packages/kivy/lang.py", line 1185, in __init__
self.parse(content)
File "/home/afidegnum/gsam/local/lib/python2.7/site-packages/kivy/lang.py", line 1287, in parse
objects, remaining_lines = self.parse_level(0, lines)
File "/home/afidegnum/gsam/local/lib/python2.7/site-packages/kivy/lang.py", line 1384, in parse_level
level + 1, lines[i:], spaces)
File "/home/afidegnum/gsam/local/lib/python2.7/site-packages/kivy/lang.py", line 1384, in parse_level
level + 1, lines[i:], spaces)
File "/home/afidegnum/gsam/local/lib/python2.7/site-packages/kivy/lang.py", line 1437, in parse_level
if current_property[:3] == 'on_':
TypeError: 'NoneType' object has no attribute '__getitem__'
do I need to define a function on_release in python code?
Upvotes: 2
Views: 2489
Reputation: 135
I have worked on your code and produce a working one. Aside the suggestions given above, I have also noticed in your .kv file, there were lots of indentation problems. I gave comments wherever necessary I made those changes. Find the working code below:
main.py
from kivy.app import App
from kivy.uix.boxlayout import BoxLayout
from kivy.uix.screenmanager import Screen, ScreenManager, FadeTransition
class MyScreenManager(ScreenManager):
pass
class MainScreen(Screen):
pass
class MailScreen(Screen):
pass
class ChatScreen(Screen):
pass
class ProjectScreen(Screen):
pass
class IntroScreen(Screen):
pass
class GsaMain(BoxLayout):
pass
class GsamApp(App):
def build(self):
sm = MyScreenManager()
sm.add_widget(IntroScreen(name="introscreen"))
sm.add_widget(MainScreen(name="main"))
sm.add_widget(MailScreen(name="mailscreen"))
sm.add_widget(ProjectScreen(name="prjcscreen"))
sm.add_widget(ChatScreen(name='chat'))
return sm
GsamApp().run()
gsma.kv
<IntroScreen>:
name: 'introscreen'
BoxLayout:
orientation: 'vertical'
padding: 100,100
spacing: 50
Label:
text: 'Welcome to GSAM'
font_size: 35
Label:
text: "Login"
TextInput:
id: login
text: "Login"
# BoxLayout: # this makes the button widget covers the whole page. remove it
Button:
text: "Connect"
on_release: app.root.current = 'main'
Button:
text: 'Project Page'
font_size: 15
on_release: app.root.current = 'prjcscreen'
<MainScreen>:
name: 'main'
BoxLayout:
orientation:'vertical'
padding:100,100
spacing:50
Label:
text: 'Your GSAM Portal'
font_size: 35
# BoxLayout: # remove this. Dont repeat BoxLayout for every widget u want show on the screen except for a good reason. Or better still, ident the BoxLayout as a child of the First Boxlayout
Button:
text: 'Check Mails' # text, font_size,on_realease must not be in the same line with button
font_size: 25
on_release: app.root.current = 'mailscreen'
canvas.before:
Color: # I have reidented Color
rgba: 1,0,0,1 # this line must be here
Rectangle: # Rectangle must ident with Color
size: 50, 50
# Label: "Post Projects" # remove the label here
id: projct # and place it either before of after canvas class
Rectangle:
size: 50, 50
# Label: "Messages"
id: msgs
<MailScreen>:
name: 'mailscreen'
BoxLayout:
Label:
text: 'GSAM Mail'
font_size: 35
Button:
text: 'Chat'
font_size: 25
on_release: app.root.current = 'chat'
<ChatScreen>:
name: 'chatscreen'
BoxLayout:
Label:
text: 'Chat with \nyour Colleagues'
font_size: 35
Button:
text: 'Home'
font_size: 25
on_release: app.root.current = 'main'
<ProjectScreen>:
name: 'prjcscreen'
BoxLayout:
Label:
text: 'Community Projects'
font_size: 35
Button:
text: 'community Projects'
font_size: 25
on_release: app.root.current = 'main'
GridLayout:
cols: 2
rows: 4
padding: 5
spacing: 5
Label:
text: "Project Title"
TextInput:
id: ptitle
Label:
text: "Project Description"
TextInput:
id: pdescr
Upvotes: 1
Reputation: 369074
There's no ChatScreen
. Define one:
class ChatScreen(Screen):
pass
ProjectScreen
should be renamed to PrjcScreen
to match the name in gsam.kv
. (Or Change PrjcScreen
in gsam.kv
)
color
-> Color
:
color: rgba: 1,0,0,1
->
Color:
rgba: 1,0,0,1
Rectangle
does not have Label
parameters:
Rectangle:
size: 50, 50
# Label: "Post Projects" <---
id: projct
Rectangle:
size: 50, 50
# Label: "Messages" <---
id: msgs
Upvotes: 2