2

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

2 Answers 2

2

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

I think solves your issue

Sign up to request clarification or add additional context in comments.

1 Comment

Yes.. This is exactly what I needed. Thank you so much
2

You are calling the function immediately, self.onefunction(params). Try removing the parenthesis - this will keep it as a function rather than the return of the function

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)

If you need to pass in params, please check Joran's answer

2 Comments

Oh yeah. Thank you .. I thought that passing parameters directly wont start it itself. So Thank You so much :)
No worries - If I helped, please upvote this answer so others will be :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.