There's no need to reinitialize the whole window; you can use Clear()
', Append(string item)
and AppendItems(list items)
on your wx.Choice.
Let's create wx.Choice control and modify it's items later:
import wx
class myFrame(wx.Frame):
def __init__(self):
wx.Frame.__init__(self, None, -1, 'Code Example', size=(300, 200))
panel = wx.Panel(self, -1)
sampleList = ['A', 'B', 'C', 'D']
wx.StaticText(panel, -1, "Select option:", (15, 20))
self.myChoice=wx.Choice(panel, -1, (85, 18), choices=sampleList)
self.myChoice.Bind(wx.EVT_SET_FOCUS,self.onFocus)
# options available in drop down list: A,B,C,D
def onFocus(self,evt):
# refresh your items with .Clear, .Append(), etc
# I'm just adding new item every time user clicks on control
self.myChoice.Append('''I'm new here''')
app = wx.PySimpleApp()
myFrame().Show()
app.MainLoop()
etc.
Personally, I'd avoid refreshing list everytime user clicks on Choice widget; that creates unnecessary queries. Instead, I'd rather re-fill choices after clicking e.g. refresh button next to your choices widget, or - if you can open your choices modification frame as a dialog - after closing data modification dialog.