How do I create a toggle button

You can create a toggle button using wx.ToggleButton. A toggle button looks exactly like a text button, but behaves more like a checkbox in that it gives a visual cue to a selected or unselected state. In other words, when you press a toggle button, it shows its state by continuing to look pressed until you click it again.

There are only two differences between a wx.ToggleButton and the parent wx.Button class :

■ A wx.ToggleButton sends an EVT_TOGGLEBUTTON event when clicked.

■ A wx.ToggleButton has GetValue() and SetValue() methods, which manipulate the binary state of the button.

Toggle buttons can be a useful and attractive alternative to checkboxes, especially in a toolbar. Remember, you cannot combine a toggle button with a bitmap button using the wxWidgets provided objects, but wxPython has a generic button class that provides this behavior, which we'll describe in the next section.

+2 -1

Responses

  • angelina
    Is wxpython togglebutton useful?
    8 years ago

Post a comment