Search code examples
pythoninheritancewxpython

Preselected Radio Button Not Functioning wxPython


I'm working to develop an application where the user enters information into text boxes that are generated when a radio button is selected and the information would be stored in a CSV file. When the application is opened, the first radio button is selected. While this is not an issue, none of the text boxes appear. If one of the radio buttons is selected then the first one is selected the text boxes appear no problem.

Here is the code that generate the radio buttons:

    self.radioStaticBox = wx.StaticBox(self.panel,-1,"Material Type: ")
    self.radioStaticBoxSizer = wx.StaticBoxSizer(self.radioStaticBox, wx.VERTICAL)
    self.radioBox = sc.SizedPanel(self.panel, -1)
    self.radioBox.SetSizerType("horizontal")
    self.isoRadioButton = wx.RadioButton(self.radioBox,-1, "Isotropic")
    self.orthoRadioButton = wx.RadioButton(self.radioBox,-1, "Orthotropic")
    self.orthotRadioButton = wx.RadioButton(self.radioBox,-1, "Orthotropic (with thickness)")
    self.isoRadioButton.SetValue(True)
    self.radioBox.Bind(wx.EVT_RADIOBUTTON, self.set_type)

And the function that the radio buttons are being bound to:

def generate_params(self, event):
    self.matStaticBoxSizer.Clear(True)
    if self.matType == "Iso":

        idSb = wx.StaticBox(self.panel, 0, "Name:")
        idSbs = wx.StaticBoxSizer(idSb, wx.HORIZONTAL)
        self.idText = wx.TextCtrl(self.panel)
        idSbs.Add(self.idText, 0, wx.ALL|wx.LEFT, self.margin)
        ....

Thanks for the help!


Solution

  • In short, you appear to be defining part of the display in the initial section of your code and then another section in the define function generate_params, this will by definition, excuse the pun, ensure that you do not see what is defined there until that function executes.
    Define all of the display items together in the initial section and then populate them within your functions, as appropriate to the function.
    In other words, define the screen in one place, the beginning, populate values as and when.