Note that there are some explanatory texts on larger screens.

plurals
  1. PODynamic radio button creation
    text
    copied!<p>In wxPython, if I create a list of radio buttons and place the list initially, is it possible to change the contents in that list later?</p> <p>For example, I have a panel that uses a boxSizer to place the widgets initially. One of those widgets is a list of radio buttons (I have also tried a normal radiobox). I would like to dynamically change the list based on variables from another class.</p> <p>However, once the list is placed in the sizer, it's effectively "locked"; I can't just modify the list and have the changes appear. If I try re-adding the list to the sizer, it just gets put in the top left corner of the panel.</p> <p>I'm sure I could hide the original list and manually place the new list in the same position but that feels like a kludge. I'm sure I'm making this harder than it is. I'm probably using the wrong widgets for this, much less the wrong approach, but I'm building this as a learning experience.</p> <pre><code> class Job(wiz.WizardPageSimple): """Character's job class.""" def __init__(self, parent, title, attribs): wiz.WizardPageSimple.__init__(self, parent) self.next = self.prev = None self.sizer = makePageTitle(self, title) self.charAttribs = attribs #---Create widgets self.Job_list = ["Aircraft Mechanic", "Vehicle Mechanic", "Electronics Specialist"] box1_title = wx.StaticBox( self, -1, "" ) box1 = wx.StaticBoxSizer( box1_title, wx.VERTICAL ) grid1 = wx.BoxSizer(wx.VERTICAL) for item in self.Job_list: radio = wx.RadioButton(self, -1, item) grid1.Add(radio) ##Debugging self.btn = wx.Button(self, -1, "click") self.Bind(wx.EVT_BUTTON, self.eligibleJob, self.btn) #---Place widgets self.sizer.Add(self.Job_intro) self.sizer.Add(self.btn) box1.Add(grid1) self.sizer.Add(box1) def eligibleJob(self, event): """Determine which Jobs a character is eligible for.""" if self.charAttribs.intelligence &gt;= 12: skillList = ["Analyst", "Interrogator", "Fire Specialist", "Aircraft Pilot"] for skill in skillList: self.Job_list.append(skill) print self.Job_list ##Debugging #return self.Job_list </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload