是否可以使用 wx.toolbar 在 wxPython 中单击后执行事件?
Is it possible to execute event after click in wxPython using wx.toolbar?
目前我正在做我的高中期末项目,我遇到了一个严重的问题。
我创建一个 wx.Toolbar,使用 wx.AddTool 添加每个选项,然后我将一些函数绑定到它,它只执行一次(在开始时)并且拒绝执行任何操作单击它之后.. 基本上...它比我想要的更早开始。
我会跳过一些代码,我只会使用需要的代码。
self.frame_toolbar.AddTool(1, "one", Base64ToImg(image1), Base64ToImage(image1-disabled), "One", "First Thing")
self.frame_toolbar.AddTool(2, "two", Base64ToImg(image1), Base64ToImage(image1-disabled), "Two", "Second Thing")
self.frame_toolbar.AddTool(3, "three", Base64ToImg(image1), Base64ToImage(image1-disabled), "Three", "Third Thing")
self.frame_toolbar.Realize()
self.SetToolBar(self.frame_toolbar)
所以现在,我的工具栏上有一些工具。现在:
self.Bind(wx.EVT_TOOL, self.onefunction(params), id=1)
self.Bind(wx.EVT_BUTTON, self.twofunction(params), id=2)
self.Bind(wx.EVT_MENU, self.threefunction(params), id=3)
还有
self.frame_toolbar.Bind(wx.EVT_TOOL, self.onefunction(params), id=1)
self.frame_toolbar.Bind(wx.EVT_BUTTON, self.twofunction(params), id=2)
self.frame_toolbar.Bind(wx.EVT_MENU, self.threefunction(params), id=3)
加载工具栏时立即执行。当我点击按钮时是否可以让它执行 ONLY?
非常感谢您的帮助。
R
self.frame_toolbar.Bind(wx.EVT_TOOL, lambda evt:self.onefunction(params), id=1)
我认为可以解决您的问题
您正在立即调用函数,self.onefunction(params)
。尝试删除括号 - 这会将其保留为函数而不是函数
的 return
self.Bind(wx.EVT_TOOL, self.onefunction, id=1)
self.Bind(wx.EVT_BUTTON, self.twofunction, id=2)
self.Bind(wx.EVT_MENU, self.threefunction, id=3)
如果需要传参,请查看Joran的回答
目前我正在做我的高中期末项目,我遇到了一个严重的问题。
我创建一个 wx.Toolbar,使用 wx.AddTool 添加每个选项,然后我将一些函数绑定到它,它只执行一次(在开始时)并且拒绝执行任何操作单击它之后.. 基本上...它比我想要的更早开始。
我会跳过一些代码,我只会使用需要的代码。
self.frame_toolbar.AddTool(1, "one", Base64ToImg(image1), Base64ToImage(image1-disabled), "One", "First Thing")
self.frame_toolbar.AddTool(2, "two", Base64ToImg(image1), Base64ToImage(image1-disabled), "Two", "Second Thing")
self.frame_toolbar.AddTool(3, "three", Base64ToImg(image1), Base64ToImage(image1-disabled), "Three", "Third Thing")
self.frame_toolbar.Realize()
self.SetToolBar(self.frame_toolbar)
所以现在,我的工具栏上有一些工具。现在:
self.Bind(wx.EVT_TOOL, self.onefunction(params), id=1)
self.Bind(wx.EVT_BUTTON, self.twofunction(params), id=2)
self.Bind(wx.EVT_MENU, self.threefunction(params), id=3)
还有
self.frame_toolbar.Bind(wx.EVT_TOOL, self.onefunction(params), id=1)
self.frame_toolbar.Bind(wx.EVT_BUTTON, self.twofunction(params), id=2)
self.frame_toolbar.Bind(wx.EVT_MENU, self.threefunction(params), id=3)
加载工具栏时立即执行。当我点击按钮时是否可以让它执行 ONLY?
非常感谢您的帮助。 R
self.frame_toolbar.Bind(wx.EVT_TOOL, lambda evt:self.onefunction(params), id=1)
我认为可以解决您的问题
您正在立即调用函数,self.onefunction(params)
。尝试删除括号 - 这会将其保留为函数而不是函数
self.Bind(wx.EVT_TOOL, self.onefunction, id=1)
self.Bind(wx.EVT_BUTTON, self.twofunction, id=2)
self.Bind(wx.EVT_MENU, self.threefunction, id=3)
如果需要传参,请查看Joran的回答