【问题标题】:Kivy module, getting text inputKivy 模块,获取文本输入
【发布时间】:2020-08-21 07:51:50
【问题描述】:

我是 Kivy 的新手,我正在尝试编写一个简单的登录系统。我从 TextInput 获取文本时遇到问题。这是代码:

class MyGrid(Widget):
passw = ObjectProperty(None)

def pressing(self):
    p = self.passw.text
    print("Name: ", p)

class MainWindow(Screen):

    grid = MyGrid()

    def wrong(self):
        show_popup()

从我写的 .kv 文件中:

<MainWindow>:
name: "main"
GridLayout:

    passw:passw

    cols: 1

    GridLayout:
        cols: 2
        Label:
            text: "Enter password: "
        TextInput:
            id: passw
            multiline: False
    Button:
        text: "Submit"
        on_release:
            root.grid.pressing()
            app.root.current = "second" if passw.text == "something" else root.wrong()
            root.manager.transition.direction = "left"

问题是当我按下按钮时,它会在控制台上崩溃:

p = self.passw.text
AttributeError: 'NoneType' object has no attribute 'text'

感谢您的帮助。

【问题讨论】:

    标签: python kivy


    【解决方案1】:

    您需要使用self.root.ids.passw.text 而不是self.passw.text

    【讨论】:

      猜你喜欢
      • 2021-01-24
      • 2015-11-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-12-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多