使用wxpython重新绑定按钮

时间:2010-09-09 22:39:57

标签: python wxpython

我有这个按钮:

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

并且需要将它绑定到另一个函数whenspecifc选择单选按钮:

def onRadiobutton(self,event) :

 if choosen radio button :

     bind the mybutton to another function 

我该怎么做?

1 个答案:

答案 0 :(得分:4)

您可以使用Unbind()方法从处理程序中取消绑定按钮,然后绑定到您想要的其他正常方法。

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)