Python 如何使用Kivy获取textinput的值

Python 如何使用Kivy获取textinput的值,python,python-2.7,kivy,Python,Python 2.7,Kivy,我是Kivy的新手,由于我不能在PySide上练习(一些动态库坏了,或者我不知道是什么),我想试试这个巨大的工具 我现在迷路了,我试着这样做: 但我不是这样做的: <ProduitScreen>: GridLayout: rows: 3 cols: 2 padding: 10 spacing: 10 Label: font_size: 20 tex

我是Kivy的新手,由于我不能在PySide上练习(一些动态库坏了,或者我不知道是什么),我想试试这个巨大的工具

我现在迷路了,我试着这样做:

但我不是这样做的:

<ProduitScreen>:
    GridLayout:
        rows: 3
        cols: 2
        padding: 10
        spacing: 10
        Label:
            font_size: 20
            text: 'Nom du produit'
        TextInput:
            font_size: 20
            id: nom
        Label:
            font_size: 20
            text: 'Prix'
        TextInput:
            font_size: 20
            id: prix
        Button:
            text: 'Ajouter'
            on_press: self.ajouter()
        Button:
            text: 'Quitter'
            on_press: root.manager.current = 'menu'
在我的课堂上,它的定义如下:

class ProduitScreen(Screen):
    def ajouter():
        print "%s au prix de %d a ete ajoute" % (self.nom.txt , float(self.prix.txt))
有人能告诉我怎么做吗


编辑:黑引号不保存缩进,因此存在完整的代码

ajourner
方法是
ProduitScreen
按钮的成员,因此您应该使用
根目录
来引用它:

    Button:
        text: 'Ajouter'
        on_press: root.ajouter()
还可以解决有关
ajouter
定义的问题:

class ProduitScreen(Screen):
    def ajouter(self):
        print "%s au prix de %f a ete ajoute" % (self.nom.text , float(self.prix.text))
要在python代码中使用
nom
prix
,请将以下内容添加到kv代码中:

<ProduitScreen>:
    nom: nom
    prix: prix
:
诺姆:诺姆
大奖赛

它绝对有效!我可以使用on_press调用什么函数来退出应用程序?(android、unix、windows等的通用功能…)从kivy.app导入应用尝试
;App.get_running_App().stop()
Awesome。如果我在使用Kivy时遇到困难,我会和你说几句话。谢谢你,老兄,还有一个问题。现在我知道了如何从GUI中获取数据,如何将数据使用到GUI中?我有一个列表,我想从中生成按钮和标签。怎么做?^^。详细说明,如果你觉得解释是大的,我建议问它作为新的问题,我会很高兴回答你和这么多其他用户。
<ProduitScreen>:
    nom: nom
    prix: prix