Shane
Shane

Reputation: 4983

How do I disable a button after it's clicked in wxpython?

There are two buttons in my little program, start and stop. And what I want is to disable the start button after I click it, and when I hit the stop button it should return to normal. How can I do this? I googled for a while and couldn't find the answer, hope you guys can help me out. Thanks!

Upvotes: 2

Views: 8415

Answers (2)

jykim31337
jykim31337

Reputation: 13

You typically control the enable and disable properties of a button control like this

class yourForm ( wx.Frame ):
def __init__( self, parent ):
...
...
...
# Connect Events
self.btnStart.Bind( wx.EVT_BUTTON, self.OnButtonClick_btnStart )
self.btnStio.Bind( wx.EVT_BUTTON, self.OnButtonClick_btnStop )


# Virtual event handlers, override them in your derived class
def OnButtonClick_btnStart( self, event):
    self.btnStart.Disable();
def OnButtonClick_btnStop( self, event):
    self.btnStart.Enable();

Upvotes: 0

ars
ars

Reputation: 123508

Use the button's Enable and Disable methods in the appropriate event handlers. There's a sample available at the link below:

wxPython Button Demo

In this snippet we are playing around with wxPython's buttons, showing you how to bind the mouse click event, enable and disable, show and hide the buttons. Each button also has a tool-tip (hint) associated with itself.

Upvotes: 3

Related Questions