我是Kivy新手,由于我不能在PySide上实践(一些动态库坏了或者我不知道是什么),我想试试这个巨大的工具。在
我现在迷路了,我试着这样做: Get textinput value in Kivy app
但我的方法不同:
<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'
因此,用“Ajouter”填充字段文本的按钮必须允许我获取两个字段的值并将它们添加到列表中,但是:
^{pr2}$在我的课上它是这样定义的:
class ProduitScreen(Screen):
def ajouter():
print "%s au prix de %d a ete ajoute" % (self.nom.txt , float(self.prix.txt))
有人能告诉我怎么做吗?在
编辑:黑引号不保存缩进,所以有完整的代码http://pastebin.com/W1WJ8NcL
ajouter
方法是ProduitScreen
而不是{root
来引用它:同时修复
^{pr2}$ajouter
定义中的问题:为了在python代码中使用
nom
和prix
,请将以下内容添加到kv代码中:相关问题 更多 >
编程相关推荐