【发布时间】:2020-04-23 18:16:59
【问题描述】:
我在 add_row 函数中动态创建添加到此滚动视图列表中的行,它看起来/工作得非常好。问题是行有按钮,我希望这些按钮具有绑定到它们的事件/操作。我试过放 on_release,但它抛出了这个错误:
File "kivy\_event.pyx", line 419, in kivy._event.EventDispatcher.bind
AssertionError: None is not callable
我不知道怎么做,所以我可以将按钮绑定到某个东西,同时仍然保持动态结构。请帮忙!这是我的代码:
def add_row(self, profile, user_id, user_name, percent):
layout = GridLayout(rows=1, row_force_default=True, row_default_height=60)
layout.add_widget(ImageButton(source=profile))
layout.add_widget(Label(text="@" + user_name, color=(0, 0, 0, 1), font_size=20))
layout.add_widget(Label(text=str(user_id), color=(0, 0, 0, 0), font_size=20))
bsplit = GridLayout(rows=1)
bsplit.add_widget(Button(background_normal='images/buttonbackgrounds/unfollow.png',
background_down='images/buttonbackgrounds/unfollow_select.png', size_hint_x=None, width=100, id=str(user_id), on_release=self.unfollow()))
bsplit.add_widget(Button(background_normal='images/buttonbackgrounds/waitlist.png',
background_down='images/buttonbackgrounds/waitlist_select.png', size_hint_x=.5, border=(3,3,3,3), id=str(user_id)))
layout.add_widget(bsplit)
self.ids.widget_list.add_widget(layout)
self.update_percent(percent)
def unfollow(self):
print(self)
【问题讨论】:
标签: python events kivy grid-layout