From the course: Rapid Application Development with Python

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

More on buttons

More on buttons - Python Tutorial

From the course: Rapid Application Development with Python

Start my 1-month free trial

More on buttons

- [Teacher] Let's take a look at how we might activate and deactivate buttons. I'll add a second button for state change. I'll put this immediately below line seven. I'll call it b_state, and it's a type wx. Button again, self.panel, wx.ID_ANY, and the text on it will be "Disable," and I'll position it at 60, 20. I'll bind it to an event handler, again, of type wx.EVT_BUTTON, and this time it will be self.on_state, and it will bind to self.b_state, our state button. And I'll add an event handler for it. def on_state(self, event). In the event handler, I'll check its current state and switch it. I can do this using the GetLabel method. If self.b_state.GetLabel() is "Disable," it's currently enabled. So the button press needs to disable it and change the text on the button. self.b_test.Disable(). self.b_state.SetLabel(), and we'll set it to "Enable." Otherwise, we'll self.b_test.Enable(), and self.b_state.SetLabel()…

Contents