Kivy, TypeError: el objeto ‘NoneType’ no tiene ningún atributo ‘__getitem__’

Al tratar de ejecutar una aplicación kivy de muestra, estoy enfrentando el error anterior.

Aquí está el código de python:

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() 

el archivo kivy llamado gsam.kv

 MyScreenManager: IntroScreen: MainScreen: PrjcScreen: MailScreen: ChatScreen: : 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' : 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 : name: 'mailscreen' BoxLayout: Label: text: 'GSAM Mail' font_size: 35 BoxLayout: Button: text: 'Chat' font_size: 25 on_release: app.root.current = 'chat' : 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' : 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 

No puedo averiguar a qué apunta el rastro.

  Traceback (most recent call last): File "main.py", line 28, in  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__' 

¿Necesito definir una función on_release en código python?

main.py

  • No hay ChatScreen . Definir uno:

     class ChatScreen(Screen): pass 
  • ProjectScreen debe cambiarse a PrjcScreen para que coincida con el nombre en gsam.kv (O cambie PrjcScreen en gsam.kv )

gsam.kv

  • color -> Color :

     color: rgba: 1,0,0,1 

    ->

     Color: rgba: 1,0,0,1 
  • Rectangle no tiene parámetros de Label :

      Rectangle: size: 50, 50 # Label: "Post Projects" <--- id: projct Rectangle: size: 50, 50 # Label: "Messages" <--- id: msgs 

He trabajado en tu código y produzco uno que funcione. Aparte de las sugerencias dadas anteriormente, también noté que en su archivo .kv, hubo muchos problemas de sangrado. Hice los comentarios donde sea necesario, hice esos cambios. Encuentra el código de trabajo a continuación:

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

 : 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' : 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 : name: 'mailscreen' BoxLayout: Label: text: 'GSAM Mail' font_size: 35 Button: text: 'Chat' font_size: 25 on_release: app.root.current = 'chat' : name: 'chatscreen' BoxLayout: Label: text: 'Chat with \nyour Colleagues' font_size: 35 Button: text: 'Home' font_size: 25 on_release: app.root.current = 'main' : 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