3

Hello I have one main frame and a button which when its pressed a second frame opens. The second frame have 6 radio buttons. My question is when I choose a radiobutton different from the allready selected and close the frame and when I open it again (without close the entire program) why is selected the first one and how can I keep my new selection?

Here is some part of the seconds frame code:

    self.radio1 = wx.RadioButton(self, label="1 sec",pos=(35,35),)
    self.Bind(wx.EVT_RADIOBUTTON, self.SetLab1, id=self.radio1.GetId())

    self.radio2 = wx.RadioButton(self, label="2 sec",pos=(35,55))
    self.Bind(wx.EVT_RADIOBUTTON, self.SetLab2, id=self.radio2.GetId())

    self.radio3 = wx.RadioButton(self, label="4 sec",pos=(35,75))
    self.Bind(wx.EVT_RADIOBUTTON, self.SetLab3, id=self.radio3.GetId())
                                  .
                                  .
                                  .

    self.button0=AB.AquaButton(self,label="Exit",pos=(115,142),size=(90,35))
    self.Bind(wx.EVT_BUTTON, self.OnButton0, self.button0)

def OnButton0(self, event):
    self.Close()

def SetLab1(self,event):
    global Delay
    Delay = 'A2/'

def SetLab2(self,event):
    global Delay
    Delay = 'A3/'

def SetLab3(self,event):
    global Delay
    Delay = 'A4/'
4

1 回答 1

3

如果你关闭框架,你会破坏它,当你再次构建它时,它会回到它的默认状态。

您可以执行以下操作:

self.radio1 = wx.RadioButton(self, label="1 sec",pos=(35,35),)
self.Bind(wx.EVT_RADIOBUTTON, self.SetLab1, id=self.radio1.GetId())

self.radio2 = wx.RadioButton(self, label="2 sec",pos=(35,55))
self.Bind(wx.EVT_RADIOBUTTON, self.SetLab2, id=self.radio2.GetId())

self.radio3 = wx.RadioButton(self, label="4 sec",pos=(35,75))
self.Bind(wx.EVT_RADIOBUTTON, self.SetLab3, id=self.radio3.GetId())
global Delay
if Delay is not None:
     getattr(self,"radio"+str(int(Delay[1])-1)).SetValue(True) 

这将选择与全局延迟变量中的值匹配的单选按钮。

一个更简单的解决方案不是“关闭”框架,而是隐藏它

#instead of my_frame.Close() (or my_frame.Destroy())
my_frame.Hide()

这保留了构造的框架,因此当您下次显示它时,它仍然具有所有值

于 2013-11-13T17:28:33.673 回答