Kivy 触发器 on_release 自动不同于 KV 语言
Kivy trigger on_release automatically different than on KV language
我的 KV 语言如下:
TabbedPanelItem:
text: 'Item 2'
on_release: print('foo')
如果我点击我的选项卡项,我会收到一条正确的消息 (foo)。
但是如果我尝试在我的 python 代码上调用 on_release
方法,它不起作用。像这样:
else:
tabbed_panel = self.parent.parent
tabbed_panel.tab_list[1].on_release()
我这样做是因为如果我调用 tabbed_panel.switch_to(tabbed_panel.tab_list[1])
,它不会调用我的选项卡项的 on_release
方法。
我究竟做错了什么?我必须做些什么来修复它?是否有其他一些行为,如 on_switch
?
如果你想触发一个Kivy widget的事件,首先检查是否有这样的even。如果是,那么只需使用 dispatch
即可触发它。
示例:
tabbed_panel.tab_list[1].dispatch('on_release')
on_release
方法意味着释放 touch(从小部件区域),而不是从 ScreenManager
释放 Screen
. switch_to
只是为了把一个Screen
换成另一个。
我的 KV 语言如下:
TabbedPanelItem:
text: 'Item 2'
on_release: print('foo')
如果我点击我的选项卡项,我会收到一条正确的消息 (foo)。
但是如果我尝试在我的 python 代码上调用 on_release
方法,它不起作用。像这样:
else:
tabbed_panel = self.parent.parent
tabbed_panel.tab_list[1].on_release()
我这样做是因为如果我调用 tabbed_panel.switch_to(tabbed_panel.tab_list[1])
,它不会调用我的选项卡项的 on_release
方法。
我究竟做错了什么?我必须做些什么来修复它?是否有其他一些行为,如 on_switch
?
如果你想触发一个Kivy widget的事件,首先检查是否有这样的even。如果是,那么只需使用 dispatch
即可触发它。
示例:
tabbed_panel.tab_list[1].dispatch('on_release')
on_release
方法意味着释放 touch(从小部件区域),而不是从 ScreenManager
释放 Screen
. switch_to
只是为了把一个Screen
换成另一个。