2

I have this button :

 self.mybutton= wx.Button(self, -1, label= "mylabel", pos=(100,180))
 self.Bind(wx.EVT_BUTTON, self.Onbutton, self.mybutton)

and need to Bind it to another function whenspecifc radio button is choosen for exmaple :

def onRadiobutton(self,event) :

 if choosen radio button :

     bind the mybutton to another function 

How can i do it ?

1 Answer 1

4

You can use the Unbind() method to unbind your button from its handler then just bind to what ever other method you want the normal way.

def onButton(self, event):
    if yourRadioButton.GetValue() == True:
        self.Unbind(wx.EVT_BUTTON, handler=self.onButton, source=self.myButton)
        self.Bind(wx.EVT_BUTTON, self.someOtherHandler, self.myButton)
Sign up to request clarification or add additional context in comments.

2 Comments

You don't even have to Unbind -- Bind() will overwrite the previously bound function.
@Steven: Im no expert but it doesn't seem to overwrite the previous function. If you put event.Skip() in the new handler onButton() still gets called after... so to me it seems safer to call Unbind() although in most cases you would probably get way it if you left it out.

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.