Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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')
like image 757
LukeG Avatar asked Dec 08 '25 03:12

LukeG


1 Answers

you just need to use GetValue() method. look at this example from wxpython wiki:

#!/usr/bin/python

# checkbox.py

import wx

class MyCheckBox(wx.Frame):
    def __init__(self, parent, id, title):
        wx.Frame.__init__(self, parent, id, title, size=(250, 170))

        panel = wx.Panel(self, -1)
        self.cb = wx.CheckBox(panel, -1, 'Show Title', (10, 10))
        self.cb.SetValue(True)

        wx.EVT_CHECKBOX(self, self.cb.GetId(), self.ShowTitle)

        self.Show()
        self.Centre()

    def ShowTitle(self, event):
        if self.cb.GetValue():#here you check if it is true or not
            self.SetTitle('checkbox.py')
        else: self.SetTitle('')


app = wx.App(0)
MyCheckBox(None, -1, 'checkbox.py')
app.MainLoop()
like image 65
Moj Avatar answered Dec 10 '25 16:12

Moj