【发布时间】:2016-01-14 21:18:28
【问题描述】:
我在 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
【问题讨论】:
-
幸运的是我在另一个项目中找到了解决方案:stackoverflow.com/a/32090870/5708480