wxpython,将数据传递给 self.Bind 中的函数 [英] wxpython, passing data to a function in self.Bind

查看:37
本文介绍了wxpython,将数据传递给 self.Bind 中的函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我很难找到答案,不知道是否可行.我查看了 wxpython 演示并进行了一些谷歌搜索,但无济于事.

I'm having trouble finding the answer to this to know if its possible. Ive looked in the wxpython demo and done some googling to no avail.

如何在绑定动作时向函数调用传递某种数据?

how do I pass some sort of data to the function call when I am binding actions?

例如

self.Bind(wx.EVT_MENU, self.DoThis, item1)

self.Bind(wx.EVT_MENU, self.DoThis, item1)

self.Bind(wx.EVT_MENU, self.DoThis, item2)

self.Bind(wx.EVT_MENU, self.DoThis, item2)

我有一组菜单选项,我希望由同一个函数 (DoThis) 处理,但需要向该函数传递一些数据,因为它的输出取决于选择的菜单项.

I have a set of menu options that I want to be handled by the same function (DoThis), but need to pass that function some data because its output depends on which menu item was selected.

我知道我可以将每个菜单项绑定到不同的功能,因此可以多次复制它,但是为了清晰和代码长度,在同一个功能中处理它会更简单,因为我有大约十几个菜单项.这甚至可能吗?谢谢

I know I can just bind each menu item to a different function so could just replicate it a bunch of times, but for the sake of clarity and length of code, it would be much simpler to handle it all in the same function, because I have about a dozen menu items. Is this even possible? Thanks

推荐答案

一个相关的问题是 是否可以将参数传递给事件绑定?.这可以通过将参数传递给回调来实现,如您所见将参数传递给回调.

a related question is Is it possible to pass arguments into event bindings?. This can do it by passing arguments to callback, as you can see to passing arguments to callbacks.

这篇关于wxpython,将数据传递给 self.Bind 中的函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆