Kivy中的未知类异常即使已定义

时间:2018-02-22 13:10:12

标签: python python-3.x user-interface kivy kivy-language

所以我在这里关注了一个解释如何在2个kivy屏幕之间共享变量的线程,但是当我尝试执行它时提供的示例时,我收到了一个错误说:

 kivy.factory.FactoryException: Unknown class <MenuScreen>

以下代码:

from kivy.app import App
from kivy.uix.boxlayout import BoxLayout
from kivy.uix.screenmanager import ScreenManager, Screen
from kivy.lang.builder import Builder
from kivy.properties import StringProperty

kv = Builder.load_string('''
#: import ScreenManager kivy.uix.screenmanager.ScreenManager
#: import Screen kivy.uix.screenmanager.ScreenManager
#: import SettingsScreen screen

ScreenManager:
    id: screen_manager
    MenuScreen:
        id: menu_screen
        name: 'MenuScreen'
        manager: screen_manager
    SettingsScreen:
        name: 'SettingsScreen'
        manager: screen_manager
        label_text: menu_screen.text

<MenuScreen>:
    BoxLayout:
        Button:
            text: 'Goto nn'
            on_press:
                root.change_text()

<SettingsScreen>:
    BoxLayout:
        Label:
            text: root.label_text
''')

class MenuScreen(Screen):
    text = StringProperty('')
    def change_text(self):
        self.text = "The text you want to set"
        self.manager.current = "SettingsScreen"

class SettingsScreen(Screen):
    label_text = StringProperty('')


class TourismChatApp(App):
    def build(self):
        return kv

if __name__ == '__main__':
    TourismChatApp().run()

我已经明确定义了MenuScreen类,我完全迷失了。非常感谢任何帮助。

0 个答案:

没有答案