Frage

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')
War es hilfreich?

Lösung 2

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)

Andere Tipps

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()
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top