Kivy没有得到button.text值正确
问题描述:
我有一个问题,我有这样的代码:Kivy没有得到button.text值正确
for j in range(1,21):
if "Canales" in item.title:
self.btn = Button(text="Channel "+str(j), size=(590, 42),size_hint=(None, None), on_press=self.aces)
layout.add_widget(self.btn)
...
def aces(self, valor):
print self.btn.text
当我打印self.btn.text我没有得到按钮上的文字,我总是得到j的最后一个值,“channel 20”...是一个Bug?只是我的无能?...
在此先感谢
答
“self.btn”解决的就是总是最后创建的按钮,因为您将其分配到循环中,修改它的部分是'ace'的新(正确)定义,而不是绑定部分。
答
我不知道,如果是最好的解决方法,但我有fbind
self.btn = Button(text="Arenavision "+str(j), size=(590, 42),size_hint=(None, None))
self.btn.fbind('on_press', self.aces, str(j))
...
def aces(self, value,arg):
print value