我的python文件是
from kivy.app import App
from kivy.lang import Builder
from kivy.uix.screenmanager import ScreenManager, Screen, FadeTransition
from kivy.uix.widget import Widget
from kivy.graphics import Line
class MainScreen(Screen):
pass
class TaskScreen(Screen):
pass
class DefrostScreen(Screen):
pass
class ScreenManagement(ScreenManager):
pass
presentation = Builder.load_file("main3.kv")
class MainApp(App):
def build(self):
return presentation
if __name__ == "__main__":
MainApp().run()
我的kv文件是
#: import FadeTransition kivy.uix.screenmanager.FadeTransition
ScreenManagement:
transition: FadeTransition()
MainScreen:
TaskScreen:
DefrostScreen:
<MainScreen>:
name:"main"
Button:
on_release: app.root.current = "Tasks"
text: "Tasks"
font_size: 25
size_hint:0.3,0.2
pos_hint:{"left":1,"top":1}
Button:
on_release: app.root.current = "Defrost"
text: "defrost"
font_size: 25
size_hint:0.3,0.2
pos_hint:{"left":1,"top":0.8}
<TaskScreen>:
name: "Tasks"
FloatLayout:
Button:
color: 0,1,0,1
font_size: 25
size_hint: 0.3,0.2
text: "back home"
on_release: app.root.current = "main"
pos_hint: {"right":1, "top":1}
<DefrostScreen>:
name: "Defrost"
Button:
color: 0,1,0,1
font_size: 25
size_hint: 0.3,0.2
text: "back home"
on_release: app.root.current = "main"
pos_hint: {"right":1, "top":1}
我运行python文件时的错误是
Traceback (most recent call last):
File "main3.py", line 16, in <module>
presentation = Builder.load_file("main3.kv")
File "C:\python34\lib\site-packages\kivy\lang.py", line 1842, in load_file
return self.load_string(data, **kwargs)
File "C:\python34\lib\site-packages\kivy\lang.py", line 1889, in load_string
parser = Parser(content=string, filename=fn)
File "C:\python34\lib\site-packages\kivy\lang.py", line 1264, in __init__
self.parse(content)
File "C:\python34\lib\site-packages\kivy\lang.py", line 1366, in parse
objects, remaining_lines = self.parse_level(0, lines)
File "C:\python34\lib\site-packages\kivy\lang.py", line 1529, in parse_level
if current_property[:3] == 'on_':
TypeError: 'NoneType' object is not subscriptable
Press any key to continue . . .
当我使用senddex的教程时它工作但是我想调整它以便我可以使用它现在它出现了这个错误
请发送帮助
答案 0 :(得分:0)
您有错误的缩进 - name: "Defrost"
和Button:
应该有相同的缩进。