Search code examples
pythonpython-3.xwxpython

Is it possible to execute event after click in wxPython using wx.toolbar?


Currently I'm working on my Final High school project and I have a serious problem.

I create a wx.Toolbar, add each option using wx.AddTool, and then I bind some functions to it, it does all the stuff only once (at the beginning) and refuses to do anything after clicking on it.. Basically... It starts way earlier than I want to.

I will skip some code, I will only use the needed one.

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)

So now, I have toolbar with some tools on it. Now:

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)

and also

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)

executes immediately when toolbar loads. Is possible to make it execute ONLY when I click on the button?

Thank you so so so much for any help. R


Solution

  • self.frame_toolbar.Bind(wx.EVT_TOOL, lambda evt:self.onefunction(params), id=1)

    I think solves your issue