如何从 wx.RadioBox 中检索值?我有以下代码

How can I retrieve a value from wx.RadioBox? I have the following code

如何从 wx.RadioBox 中检索值?我有以下代码:

import wx

class RadioBoxFrame(wx.Frame):
def __init__(self):
    wx.Frame.__init__(self, None, -1, 'Radio Box Example', 
            size=(350, 200))
    panel = wx.Panel(self, -1)
    sampleList = ['zero', 'one', 'two', 'three', 'four', 'five',
                  'six', 'seven', 'eight']
    self.button=wx.RadioBox(panel, -1, "A Radio Box", (10, 10), wx.DefaultSize,
                    sampleList, 2, wx.RA_SPECIFY_COLS)



if __name__ == '__main__':
    app = wx.PySimpleApp()
    RadioBoxFrame().Show()
    app.MainLoop()             

我尝试了下面的代码但出现了一些错误

 self.Bind(wx.EVT_RADIOBOX, self.SetVal)
    def SetVal(self, event):
        state1 = self.button.GetSelection()
        print state1

A​​ttributeError: 'RadioBoxFrame' 对象没有属性 'SetVal'

看起来你的 SetVal 方法缩进不正确,下面的工作

import wx

class RadioBoxFrame(wx.Frame):
    def __init__(self):
        wx.Frame.__init__(self, None, -1, 'Radio Box Example',
                size=(350, 200))
        panel = wx.Panel(self, -1)
        sampleList = ['zero', 'one', 'two', 'three', 'four', 'five',
                      'six', 'seven', 'eight']
        self.button=wx.RadioBox(panel, -1, "A Radio Box", (10, 10), wx.DefaultSize,
                        sampleList, 2, wx.RA_SPECIFY_COLS)

        self.Bind(wx.EVT_RADIOBOX, self.SetVal)

    def SetVal(self, event):
        state1 = self.button.GetSelection()
        print state1



if __name__ == '__main__':
    app = wx.App()
    RadioBoxFrame().Show()
    app.MainLoop()