Search code examples
pythonwxpythonappend

wxPython checkbox true or false


So let's say that I have a checkbox in wxPython:

cb1 = wx.CheckBox(panelWX, label='TIME', pos=(20, 20))
cb1.SetValue(False)

Is there a simple way I could check to see whether it has changed to true? Like this maybe?

if cb1.SetValue == True:

And from that point append something from the action of it being true? Like so:

selectionSEM1.append('Time')

Solution

  • You want to use Events.

    def do_something(event):
        box = event.GetEventObject()
        setting = box.GetValue()
        if setting:
                selectionSEM1.append('Time')
        event.Skip()
    
    cb1.Bind(wx.EVT_CHECKBOX, do_something, cb1)