sm.current does not switch screen and gives me attribute error : 'str' object has no attribute 'current'

sm.current does not switch screen and gives me attribute error : 'str' object has no attribute 'current'

我是 Kivy 的新手,我在尝试构建登录屏幕时遇到如下错误。有人可以帮助了解出了什么问题以及需要做什么吗?

A​​ttributeError: 'str' 对象没有属性 'current'

我的 Kivy 文件如下所示

ScreenManager:
    Welcome:
    SelectionOption:


<Welcome>:
    id: welcome
    name: 'welcome'
    manager: 'sm'
    emailInput: emailInput
    passwordInput: passwordInput
    MDScreen :
        md_bg_color : [102/255,153/255,153/255,1]
        MDCard :
            size_hint : None, None
            size : 300, 450
            pos_hint : {"center_x":.5,"center_y":.5}
            padding : 20
            spacing : 30
            orientation : "vertical"

            MDLabel :
                text : 'Manager'
                font_style : 'Overline'
                font_size : 30
                halign : "center"
                size_hint_y : None
                height : self.texture_size[1]
                padding_y : 10

            MDTextFieldRound :
                id: emailInput
                hint_text : "Email address"
                icon_right : "account"
                size_hint_x : None
                width : 220
                font_size : 15
                pos_hint : {"center_x":.5}
                color_active : [0.2,0.2,0.1,1]
                TextInput:
                    multiline: False

            MDTextFieldRound :
                id: passwordInput
                hint_text : "password"
                icon_right : "eye-off"
                size_hint_x : None
                width : 220
                font_size : 15
                pos_hint : {"center_x":.5}
                color_active : [0.2,0.2,0.1,1]
                password : True
                TextInput:
                    multiline: False

            MDRoundFlatButton :
                text : 'Login'
                pos_hint : {'center_x':0.5, 'center_y':0.5}
                font_size : 20
                text_color: 0, 0, 0, 0
                on_release:
                    root.validatelogin()

            MDRoundFlatButton :
                text: 'NEW USER'
                pos_hint: {'center_x':.5, 'center_y':0.4}
                font_size: 20
                text_color: 0, 0, 0, 0
                on_press:
                    root.signup()

            Widget :
                size_hint_y : None
                height : 30

<SelectionOption>:
    name : 'selection'
    MDLabel:
        text : 'Selection Option'
        font_style : 'Overline'
    MDRoundFlatButton :
        text: 'Login'
        pos_hint : {'center_x':0.5, 'center_y':0.5}
        font_size : 20
        text_color: 0, 0, 0, 0

我的 python 代码如下所示。

from kivymd.app import MDApp
from kivy.lang.builder import Builder
from kivy.uix.screenmanager import Screen, ScreenManager
from kivy.core.window import Window
from kivy.properties import ObjectProperty

Window.size = (350, 580)


class Welcome(Screen):
    emailInput = ObjectProperty(None)
    passwordInput = ObjectProperty(None)

    def validatelogin(self):
        if self.emailInput.text == "123" and self.passwordInput.text == "123":
            print("????", self.manager)
            self.manager.current = 'selection'


class SelectionOption(Screen):
    pass


class windowManager(ScreenManager):
    pass


class Console(MDApp):

    def build(self):
        return Builder.load_file('../Files/ScreenManager.kv')


if __name__ == '__main__':
    Console().run()
manager: 'sm'

我不知道这是干什么用的,但它编码的正是您所看到的错误。

可能只删除这一行。