【问题标题】:AttributeError: 'NoneType' object has no attribute 'text' \ KivyAttributeError:“NoneType”对象没有属性“文本”\ Kivy
【发布时间】:2021-01-31 05:07:27
【问题描述】:

在 Detail_Window() 类中,我将值 a 作为 Book_Window 类,然后我使用 b 和 c 作为 from_user 和 to_user 的值,我收到如下错误:

AttributeError: 'NoneType' 对象没有属性 'text'

请帮我解决这个问题

这是代码

在 .py 文件中

class Book_Window(Screen):
    from_user = ObjectProperty(None)
    to_user = ObjectProperty(None)


class Detail_Window(Screen):
    a = Book_Window()
    b = a.from_user.text
    c = a.to_user.text

    def check(self, value):
        if value == True and self.b == "Chennai" and self.c == "Sivakasi":
            checkcheck = "Amount : 400"
            print(checkcheck)
        else:
            checkcheck = "Amount : 600"
            print(checkcheck)

在 .kv 文件中

<Book_Window>:
    from_user: from_user
    to_user: to_user

<Detail_Window>:

    FloatLayout:

        Label:
            text: "Amount : 400" if root.b == "Chennai" and root.c == "Sivakasi" else "Amount : 600"
            font_size: 30

【问题讨论】:

  • 什么是 ObjectProperty?。我认为您的代码不完整
  • @SauravRai 我已经更新了

标签: python-3.x kivy


【解决方案1】:

这是因为在Book_Window 类中from_userto_userNone

所以None(即NoneType)没有文本值

编辑

要定义它们,您可以这样做:

class Book_Window(Screen, form_user, to_user):
    self.from_user = from_user
    self.to_user = to_user

a = Book_Window('the values you want to assign them')

【讨论】:

  • 那我该怎么办??
猜你喜欢
  • 2021-10-16
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-11-28
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多