我有一个python文件,应该在 Builder.load_string 中引用多个类 firstscreenScreen和secondscreenScreen。 但是,它执行的操作却显示错误unknow类secondscreenScreen。我猜这是因为它仅搜索头等舱,而忽略其他舱位。我在这里删除了无关紧要的代码。如何在一个buildloader中包含两个或多个文件,是否可以选择包含2 buil.load_string并且仍然能够切换屏幕?
from kivy.app import App
from kivy.uix.screenmanager import ScreenManager, Screen
from kivy.uix.widget import Widget
from kivy.uix.button import Button
from kivy.core.window import Window
from kivy.lang import Builder
from kivy.uix.button import Button
Builder.load_string("""
#:kivy 1.9.0
<firstscreenScreen>:
Word:
<secondscreenScreen>:
WordList:
Label:
id: label1
text: self.parent.txt1
""")
class Word(Widget):
pass
class firstscreenScreen(Screen):
pass
class secondscreenScreen(Screen):
pass
class ScreenManager(ScreenManager):
pass
sm = ScreenManager()
sm.add_widget(firstscreenScreen(name='firstscreen'))
sm.add_widget(secondscreenScreen(name='secondscreen'))
class WordApp(App):
def build(self):
Window.clearcolor = (0,0,0.3,1)
return sm
if __name__ == '__main__':
WordApp().run()
class WordList(Widget):
txt1 = "abc"
class firstscreenScreen(Screen):
pass
class secondscreenScreen(Screen):
pass
class WordListApp(App):
def build(self):
Window.clearcolor = (0,0,0.3,1)
return sm
if __name__ == '__main__':
WordListApp().run()
答案 0 :(得分:0)
在定义它们之前,您尝试使用这些类。将类定义移至load_string命令之前。