使用 Wxpython 从 RadioButton 组中获取选定的按钮

Get Selected Button from RadioButton Group with Wxpython

我有两个 wxpython 单选按钮组:

    self.red = wx.RadioButton(panel, -1, 'Red', (10, q2y), style=wx.RB_GROUP)
    self.orange = wx.RadioButton(panel, -1, 'Orange', (50, q2y))
    self.yellow = wx.RadioButton(panel, -1, 'Yellow', (100, q2y))

    self.dot = wx.RadioButton(panel, -1, 'Dot', (10, q3y), style=wx.RB_GROUP)
    self.triangle = wx.RadioButton(panel, -1, 'Triangle', (50, q3y))
    self.rectange = wx.RadioButton(panel, -1, 'Rectangle', (100, q3y))

有没有一种简单的方法可以在不循环遍历所有按钮的情况下从每个组中获取选定的单选按钮?

使用 wx.EVT_RADIOBUTTON 绑定并在事件处理程序中使用 event.GetEventObject 来获取选定的按钮。有关代码示例,请参阅 RadioButton 的 wxPython 演示。