Python Kivy应用程序退出屏幕更改

Python Kivy应用程序退出屏幕更改,python,python-3.x,kivy,Python,Python 3.x,Kivy,我正在尝试将我的代码从.kv文件全部移植到Python(这样对我来说似乎更容易)。我有两个屏幕,我一直在使用kv文件中的root.manager.current=“main”切换到下一个屏幕。然而,在用Python代码编写这段代码时,我的应用程序崩溃了。这是我的代码: class CustomScreenManager(ScreenManager): def switch_view(self): self.current = 'main' class Intro(Scr

我正在尝试将我的代码从.kv文件全部移植到Python(这样对我来说似乎更容易)。我有两个屏幕,我一直在使用kv文件中的
root.manager.current=“main”
切换到下一个屏幕。然而,在用Python代码编写这段代码时,我的应用程序崩溃了。这是我的代码:

class CustomScreenManager(ScreenManager):
    def switch_view(self):
        self.current = 'main'

class Intro(Screen):
    pass

class Chat(Screen):
    pass

class ChatApp(App):
    def build(self):
        Screens = CustomScreenManager(transition = NoTransition())

        intro = Intro()
        chat = Chat(name = "main")

        bt1_intro = Button(on_press = Screens.switch_view())

        intro.add_widget(bt1_intro)

        Screens.add_widget(intro)
        Screens.add_widget(chat)

        return Screens

if __name__ == "__main__":
    ChatApp().run()
    ChatApp().screen_manager

我也尝试了
切换到
的方法,但它也会使应用程序崩溃。我能做些什么来避免撞车并获得预期的行为?提前感谢。

切换视图的定义更改为

def switch_view(self, *args):
并添加
按钮

bt1_intro = Button(on_press = Screens.switch_view)

应用程序崩溃,因为在您最初分配的
bt1\u intro
switch\u view
中被调用(而不是传递给函数),并且当时屏幕不存在

当应用程序崩溃时,您是否收到任何类型的错误?您的日志文件是否包含任何相关内容?不,它只是像往常一样说“正在运行应用程序…”,尽管我的代码中没有一行应该关闭它。