5

I have a list of buttons and I have made a loop to find out what button is pressed, then disable that button on click.

Here is the snippet of code:

    def change(self,event):
        self.Disable()


    for i in enumerate(file_pool):
        self.button_pool.append(wx.Button(self.sizer, -1, i[1], pos=(20, i[0]*45),size=(200,40))) #this would create the list of buttons
    for i in self.button_pool:
        i.Bind(wx.EVT_BUTTON, self.change) #bind each button

However, this will Disable every widget, not just the pressed button. How can I only disable the clicked button?

Thanks

1 Answer 1

13

you can get your object from the event:

def change(self, event):
    myobject = event.GetEventObject()
    myobject.Disable()
Sign up to request clarification or add additional context in comments.

2 Comments

is there a way, to enable the other buttons once one button is pressed?
You can enable all of them getting them from your list of buttons in a loop but checking first if myobject == item_from_list

Your Answer

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