Python 属性错误:';非类型';对象没有属性';文本';基维

Python 属性错误:';非类型';对象没有属性';文本';基维,python,kivy,kivy-language,Python,Kivy,Kivy Language,我正试图从ABC.kv文件中的文本框中提取值。我在这里发现了一个类似的问题。我尝试应用相同的解决方案,但错误不断出现。我不知道问题的根源在哪里。有没有人能对我所面临的问题说点什么呢 ABC.py from kivy.app import App from kivy.lang import Builder from kivy.uix.button import Button from kivy.uix.label import Label from kivy.uix.boxlayout i

我正试图从
ABC.kv
文件中的文本框中提取值。我在这里发现了一个类似的问题。我尝试应用相同的解决方案,但错误不断出现。我不知道问题的根源在哪里。有没有人能对我所面临的问题说点什么呢

ABC.py

    from kivy.app import App
from kivy.lang import Builder
from kivy.uix.button import Button
from kivy.uix.label import Label
from kivy.uix.boxlayout import BoxLayout
from kivy.properties import ObjectProperty
from kivy.uix.popup import Popup
from kivy.uix.screenmanager import ScreenManager, Screen, FadeTransition

class LoginScreen(BoxLayout):
    username_input = ObjectProperty()
    passwd_input = ObjectProperty()

    def __init__(self, **kwargs):
        super(LoginScreen, self).__init__(**kwargs)


        boxp = BoxLayout(orientation='vertical')
        labs = Label(text='')
        self.boxp = BoxLayout(orientation='vertical')
        self.labs = Label(text='')
        self.boxp.add_widget(self.labs)

        self.box = BoxLayout()
        self.box.orientation = 'horizontal'
        btn5 = Button(text="ok", size_hint=(0.5, 0.5))
        btn5.bind(on_release=self.checkin())
        self.box.add_widget(btn5)
        self.box.add_widget(Button(text='cancel', size_hint=(0.5, 0.5), on_release=self.cancel_button_hit))
        self.boxp.add_widget(self.box)
        self.popup = Popup(title="LOGIN SUCCESSFUL",
                            content=self.boxp,
                            size=(200, 200),
                            size_hint=(0.3, 0.3),
                            auto_dismiss=True)

    def checkin(self):
        if self.username_input.text=="root" and self.passwd_input.text=="root":
            self.labs.text = self.username_input.text
            self.popup.open()

        else:
            self.popup.title='Failed Login'
            self.labs.text = 'Failed'
            self.popup.open()
    def cancel_button_hit(self, instance):
        self.popup.dismiss()

class AnotherScreen(Screen):
    pass

class ScreenManagement(ScreenManager):
    pass

class MainApp(App):
    def build(self):
        return LoginScreen()

MainApp().run()
ABC.kv

#: import FadeTransition kivy.uix.screenmanager.FadeTransition
ScreenManagement:
    transition: FadeTransition()
    LoginScreen:
    AnotherScreen:

<LoginScreen>:
    orientation: "vertical"
    username_input: username
    passwd_input: passwd
    padding: 10
    spacing: 10
    name: 'login'
    BoxLayout:
        orientation: "vertical"
        Label:
            text: "Username"

        TextInput:
            id: username

        Label:
            text: "password"

        TextInput:
            id: passwd
            password: True

        Button:
            on_release: root.checkin()
            text: 'login'
            font_size: 50

<AnotherScreen>:
    name: 'other'

    Button:
        on_release: app.root.current = 'main'
        text: 'back to the home screen'
        font_size: 50
#:导入FadeTransition kivy.uix.screenmanager.FadeTransition
屏幕管理:
转换:FadeTransition()
登录筛选:
另一屏幕:
:
方向:“垂直”
用户名\输入:用户名
passwd\u输入:passwd
填充:10
间距:10
名称:“登录”
盒子布局:
方向:“垂直”
标签:
文本:“用户名”
文本输入:
id:用户名
标签:
文本:“密码”
文本输入:
id:passwd
密码:True
按钮:
发布时:root.checkin()
文本:“登录”
字体大小:50
:
姓名:'其他'
按钮:
发布时:app.root.current='main'
文本:“返回主屏幕”
字体大小:50
回溯:

Traceback (most recent call last):
   File "C:/Users/Admin/PycharmProjects/guihm/ABC.py", line 59, in <module>
     MainApp().run()
   File "C:\Python34\lib\site-packages\kivy\app.py", line 802, in run
     root = self.build()
   File "C:/Users/Admin/PycharmProjects/guihm/ABC.py", line 57, in build
     return LoginScreen()
   File "C:/Users/Admin/PycharmProjects/guihm/ABC.py", line 27, in __init__
     btn5.bind(on_release=self.checkin())
   File "C:/Users/Admin/PycharmProjects/guihm/ABC.py", line 38, in checkin
     if self.username_input.text=="root" and self.passwd_input.text=="root":
 AttributeError: 'NoneType' object has no attribute 'text'
回溯(最近一次呼叫最后一次):
文件“C:/Users/Admin/PycharmProjects/guihm/ABC.py”,第59行,在
MainApp().run()
文件“C:\Python34\lib\site packages\kivy\app.py”,第802行,正在运行
root=self.build()
文件“C:/Users/Admin/PycharmProjects/guihm/ABC.py”,第57行,内部版本
返回LoginScreen()
文件“C:/Users/Admin/PycharmProjects/guihm/ABC.py”,第27行,在__
btn5.bind(on_release=self.checkin())
签入中第38行的文件“C:/Users/Admin/PycharmProjects/guihm/ABC.py”
如果self.username\u input.text==“root”和self.passwd\u input.text==“root”:
AttributeError:“非类型”对象没有属性“文本”

用户名和密码输入丢失。移除自我。在它们中

当用户单击
弹出窗口中的
btn5
时,没有必要再次调用
签入方法。您已经在
ABC.kv
文件中的登录按钮定义中调用了它。首先,从
btn5.bind(on_release=self.checkin())
行中删除
checkin
后的括号。我建议调用不同的方法来处理
btn5
发布操作

btn5.bind(on_release=self.success)
定义一种名为
success的方法

def success(self,instance):
    self.popup1.dismiss()   

还将.kv文件中的
ScreenManagement
类括在角括号内

在做了必要的改变后,这就是我现在得到的。。。self.username\u input=ObjectProperty()name错误:名称“self”未定义已编辑我的答案请尝试