我在Kivy中创建了一个编辑窗口,允许显示字典中的内容并更改相关项目(文本)的内容。 首先,使用存储在字典中的第一个处理步骤的数据初始化所有TextInput字段。有一个按钮用于触发和显示下一步。但是用户可能同时更改特定TextInput字段的内容。更改后,新的TextInput内容应分配给局部变量(在下面的示例中以打印表示)。总之,我有以下代码。不幸的是,变量没有更新。怎么了?
python部分:
from kivy.properties import StringProperty
class pezHome(Widget):
title = StringProperty()
def init_pez(self):
self.title = "Enter your title"
def update(self):
new_title = self.title
print "New title is: ", new_title
class pezApp(App):
def build(self):
homeWin = pezHome()
homeWin.init_editor()
return homeWin
pezApp().run()
相关的kv文件:
<pezHome>:
TextInput:
text: root.title
on_text: root.title
readonly: False
答案 0 :(得分:0)
您没有调用更新方法......这是所需的更改
<pezHome>:
TextInput:
text: root.title
on_text: root.update() # was root.title ...
readonly: False