0

我有一个使用 WXPython 开发的简单 python GUI。我有一个 checkbox1、 checkbox2 和 radiobox1。根据 Checkbox2 选择,我希望启用或禁用 radiobox1。例如,如果未选中 Checkbox2,我希望禁用 radiobox1。我尝试使用 getvalue() 参数但没有成功。这是示例代码。

任何帮助深表感谢。

import wx

def create(parent):
    return Frame1(parent)

[wxID_FRAME1, wxID_FRAME1CHECKBOX1, wxID_FRAME1CHECKBOX2, 
 wxID_FRAME1NOTEBOOK1, wxID_FRAME1PANEL1, wxID_FRAME1RADIOBOX1, 
 wxID_FRAME1STATICBOX1, wxID_FRAME1STATICTEXT1, 
] = [wx.NewId() for _init_ctrls in range(8)]

class Frame1(wx.Frame):
    def _init_coll_notebook1_Pages(self, parent):
        # generated method, don't edit

        parent.AddPage(imageId=-1, page=self.panel1, select=True, text='Pages0')
        parent.AddPage(imageId=-1, page=self.staticText1, select=False,
              text='Pages1')

    def _init_ctrls(self, prnt):
        # generated method, don't edit
        wx.Frame.__init__(self, id=wxID_FRAME1, name='', parent=prnt,
              pos=wx.Point(470, 184), size=wx.Size(677, 492),
              style=wx.DEFAULT_FRAME_STYLE, title='Frame1')
        self.SetClientSize(wx.Size(661, 454))

        self.notebook1 = wx.Notebook(id=wxID_FRAME1NOTEBOOK1, name='notebook1',
              parent=self, pos=wx.Point(0, 0), size=wx.Size(661, 454), style=0)

        self.panel1 = wx.Panel(id=wxID_FRAME1PANEL1, name='panel1',
              parent=self.notebook1, pos=wx.Point(0, 0), size=wx.Size(653, 428),
              style=wx.TAB_TRAVERSAL)

        self.staticBox1 = wx.StaticBox(id=wxID_FRAME1STATICBOX1,
              label='staticBox1', name='staticBox1', parent=self.panel1,
              pos=wx.Point(16, 16), size=wx.Size(232, 128), style=0)

        self.checkBox1 = wx.CheckBox(id=wxID_FRAME1CHECKBOX1, label='checkBox1',
              name='checkBox1', parent=self.panel1, pos=wx.Point(24, 40),
              size=wx.Size(70, 13), style=0)

        self.checkBox2 = wx.CheckBox(id=wxID_FRAME1CHECKBOX2, label='checkBox2',
              name='checkBox2', parent=self.panel1, pos=wx.Point(24, 64),
              size=wx.Size(70, 13), style=0)
        self.checkBox2.Set3StateValue(1)
        self.checkBox2.Bind(wx.EVT_CHECKBOX, self.OnCheckBox2Checkbox,
              id=wxID_FRAME1CHECKBOX2)

        self.radioBox1 = wx.RadioBox(choices=['Phase A', 'PhaseB', 'Phase C'],
              id=wxID_FRAME1RADIOBOX1, label='radioBox1', majorDimension=3,
              name='radioBox1', parent=self.panel1, pos=wx.Point(32, 88),
              size=wx.Size(200, 44), style=wx.RA_SPECIFY_COLS)

        self.staticText1 = wx.StaticText(id=wxID_FRAME1STATICTEXT1,
              label='staticText1', name='staticText1', parent=self.notebook1,
              pos=wx.Point(0, 0), size=wx.Size(653, 428), style=0)

        self._init_coll_notebook1_Pages(self.notebook1)

    def __init__(self, parent):
        self._init_ctrls(parent)

    def OnCheckBox2Checkbox(self, event):
        #event.Skip()
        if self.checkBox2.GetValue() == 'False':
            self.radioBox1.Enable(False)
            print self.checkBox2.IsChecked()

if __name__ == '__main__':
    app = wx.PySimpleApp()
    frame = create(None)
    frame.Show()

    app.MainLoop()
4

1 回答 1

1

我认为你的问题是你只是在一个方向上改变事情 - 改变:

def OnCheckBox2Checkbox(self, event):
    #event.Skip()
    if self.checkBox2.GetValue() == 'False':
        self.radioBox1.Enable(False)
        print self.checkBox2.IsChecked()

到:

def OnCheckBox2Checkbox(self, event):
    self.radioBox1.Enable(self.checkBox2.IsChecked())
    print self.checkBox2.IsChecked()
于 2013-08-07T09:53:43.397 回答