我有多个收音机包含三个按钮,如下所示。我想跟踪收音机盒中点击的单选按钮,然后进行一些处理。我不知道如何索引收音机盒然后点击该收音机盒内的单选按钮,因为有多个盒子。有什么建议?
class MyFrame(wx.Frame):
def __init__(self, parent, id, title):
wx.Frame.__init__(self, parent, id, "test", wx.DefaultPosition, wx.Size(900, 600))
radio1Choices = ['F','G','P']
# rb_list has 23 records -- basically used to set the distance b/w radio boxes
for i in rb_list:
self.radio1 = wx.RadioBox(scroll1, wx.ID_ANY, wx.EmptyString, (550,i), (20,5), radio1Choices, 3, wx.RA_SPECIFY_COLS | wx.NO_BORDER)
self.radio1.SetSelection( 0 )
grid_sizer.Add( self.radio1, 0, wx.ALL, 5)
# Bind the radio box select event to a function
self.radio1.Bind( wx.EVT_RADIOBOX, self.on_selected )
def on_selected(self, event):
if self.radio1.GetStringSelection() == 'F':
print "F"
elif self.radio1.GetStringSelection() == 'G':
print "G"
else:
self.radio1.GetStringSelection() == 'P'
print "P"
答案 0 :(得分:1)
将每个radiobox附加到列表中,然后只有你可以将每个无线电盒与其事件
绑定试试这段代码:
self.radiobuttonlist=[]
for i in range(0,len(lut_code)):
rb += 40
self.radiobuttonlist.append(wx.RadioBox(scroll1, wx.ID_ANY, wx.EmptyString, (550,rb), (30,5), radio1Choices, 3, wx.RA_SPECIFY_COLS | wx.NO_BORDER))
self.radiobuttonlist[-1].SetSelection(0)
print self.radiobuttonlist[-1].GetId()
self.Bind(wx.EVT_RADIOBOX,self.Getvalues,id=self.radiobuttonlist[-1].GetId())
grid_sizer.Add(self.radiobuttonlist[-1], 0, wx.ALL, 5)
要获取所选的单选按钮值,请使用:
event.GetEventObject()。GetSelection()
试试这段代码:
def Getvalues(self,event):
print event.GetEventObject().GetSelection()