Python 基维:我怎样才能得到正确的课程?

Python 基维:我怎样才能得到正确的课程?,python,class,kivy,Python,Class,Kivy,我过去常这样做 MDApp.get_running_app().root.ids[some_id].focus = True 而且效果很好。现在我添加了一个屏幕管理器,这给了我一个错误:KeyError:'some\u id' 我试过了 MainLayout().ids[some_id].focus = True 因为screen的类是MainLayout,它不会抛出错误,但它不会做任何事情。。。另一个屏幕名为LoadingScreen,如果这很重要的话。有什么想法吗?如果您有屏幕管理器,请

我过去常这样做

MDApp.get_running_app().root.ids[some_id].focus = True
而且效果很好。现在我添加了一个屏幕管理器,这给了我一个错误:
KeyError:'some\u id'

我试过了

MainLayout().ids[some_id].focus = True

因为screen的类是MainLayout,它不会抛出错误,但它不会做任何事情。。。另一个屏幕名为LoadingScreen,如果这很重要的话。有什么想法吗?

如果您有屏幕管理器,请尝试以下方法:

ScreenManager:
        id: screenmanager
        SomeScreen:
           name: 'somescreen'
           id: somescreen

MDApp.get_running_app().root.ids['somescreen'].ids['some_id'].focus = True


所以它所做的就是转到屏幕管理器中定义的类名,并从该类中获取指定的id。请注意,您必须提供屏幕管理器中定义的名称,因为您有屏幕管理器请尝试以下操作:

ScreenManager:
        id: screenmanager
        SomeScreen:
           name: 'somescreen'
           id: somescreen

MDApp.get_running_app().root.ids['somescreen'].ids['some_id'].focus = True

所以它所做的就是转到屏幕管理器中定义的类名,并从该类中获取指定的id。请注意,您必须提供屏幕管理器中定义的名称