wxPython conditionally display and hide
Question: I am new to wxPython and would like to use it to build a simple dynamic UI
which conditionally show and hide some drop-down boxes, which can be done
easily in jQuery.

So from my first level combo-box, if a user choose 'Op1_1', a second level
combo-box A will appear. On the other hand, if 'Op1_2' is selected, at the
same location, a different second level combo-box B will be generated.

  1. Question 1: I am able to add a second level combo-box box on the fly, but its location is not correct. From the attached figure, you can see it always goes to the top left. Is there a way to re-position this?
  2. Question 2: If the first second combo-box A is generated, then the user chooses 'Op1_2', theoretically, combo-box B will replace combo-box A. But I ran into an error `wxGridBagSizer::Add(): An item is already at that position`. How to destroy a previously built box?
  3. Question 3: Is there a way to integrate wxPython and jQuery, which could make my life easier....

![enter image description here](http://i.stack.imgur.com/8SvSf.jpg)

    
    
    import wx
    
    class landing_frame(wx.Frame):
    
        def __init__(self, parent, title):    
            super(landing_frame, self).__init__(parent, title=title, 
                size=(450, 350))
            self.font1 = wx.Font(18, wx.DECORATIVE, wx.ITALIC, wx.BOLD) 
            self.InitUI()
            self.Centre()
            self.Show()     
    
        def InitUI(self):
    
            self.panel = wx.Panel(self)
            self.sizer = wx.GridBagSizer(5, 5)
    
            self.text1 = wx.StaticText(self.panel, label="Welcome!")
            self.sizer.Add(self.text1, pos=(0, 0), flag=wx.TOP|wx.LEFT|wx.BOTTOM, border=15)
    
            line = wx.StaticLine(self.panel)
            self.sizer.Add(line, pos=(1, 0), span=(1, 5), flag=wx.EXPAND|wx.BOTTOM, border=10)
    
            self.text2 = wx.StaticText(self.panel, label="First Level Dropdown")
            self.sizer.Add(self.text2, pos=(2, 0), flag=wx.LEFT, border=10)
    
            self.sampleList = ['Op1_1', 'Op1_2']
            self.combo = wx.ComboBox(self.panel, 30, choices=self.sampleList)
            self.combo.Bind(wx.EVT_COMBOBOX, self.EvtComboBox)
            self.sizer.Add(self.combo, pos=(2, 1), span=(1, 2), flag=wx.TOP|wx.EXPAND, border=5)
    
            self.panel.SetSizer(self.sizer)
    
    
        def EvtComboBox(self, event):
            self.user_choice = event.GetString()
            if self.user_choice == "Op1_1": 
                self.sampleList_ss1 = ['Op2_1_1', 'Op2_1_2', 'Op2_1_3']
                self.combo_ss1 = wx.ComboBox(self.panel, 31, choices=self.sampleList_ss1)
                self.combo_ss1.Bind(wx.EVT_COMBOBOX, self.EvtComboBox)
                self.sizer.Add(self.combo_ss1, pos=(3, 1), span=(1, 2), flag=wx.TOP|wx.EXPAND, border=5)
                self.panel.SetSizer(self.sizer)
    
            if self.user_choice == "Op1_2": 
                self.sampleList_ss2 = ['Op2_2_1', 'Op2_2_2', 'Op2_2_3']
                self.combo_ss2 = wx.ComboBox(self.panel, 31, choices=self.sampleList_ss2)
                self.combo_ss2.Bind(wx.EVT_COMBOBOX, self.EvtComboBox)
                self.sizer.Add(self.combo_ss2, pos=(3, 1), span=(1, 2), flag=wx.TOP|wx.EXPAND, border=5)
                self.panel.SetSizer(self.sizer)
    
    
    
    if __name__ == '__main__':
        app = wx.App(redirect=False, filename="mylogfile.txt")
        landing_frame(None, title="Test")
        app.MainLoop()
    


Answer:   1. Try calling self.panel.Layout(). There is no need to do self.panel.SetSizer(self.sizer) again.
  2. You can call wx.Sizer.Remove(window). wx.Sizer also has a replace function, but I am not sure how it works with a GridBagSizer. You could also create all your combo boxes, hide or disable those you do not need, and change their contents as needed (wx.ComboBox derives from wx.ControlWithItems, and has member functions Clear, Delete, Append, Insert). If you decide to delete the combo boxes, then, first Remove it from the sizer, and call Destroy.
  3. No.

