How ever my filter dropdown example working in wxpython version 4.0.7 and not in latest 4.1.1 . the problem is while assign the value to combobox event get fired and then code goes in infinite loop and closes the application. here is my sample code.
import wx
class Mywin(wx.Frame):
def init(self, parent: object, title: object) -> object:
super(Mywin, self).init(parent, title=title, size=(300, 200))
self.languages = [‘C’, ‘C++’, ‘Python’, ‘Java’, ‘Perl’]
panel = wx.Panel(self)
box = wx.BoxSizer(wx.VERTICAL)
self.label = wx.StaticText(panel, label="Your choice:", style=wx.ALIGN_CENTRE)
box.Add(self.label, 0, wx.EXPAND | wx.ALL, 20)
cblbl = wx.StaticText(panel, label="Combo box", style=wx.ALIGN_CENTRE)
box.Add(cblbl, 0, wx.EXPAND | wx.ALL, 5)
self.combo = wx.ComboBox(panel, choices=self.languages)
box.Add(self.combo, 1, wx.EXPAND | wx.ALL, 5)
box.AddStretchSpacer()
self.combo.Bind(wx.EVT_TEXT, self.oncombo)
self.ignoreEvtText = False
panel.SetSizer(box)
self.Centre()
self.Show()
def oncombo(self, event):
if self.ignoreEvtText:
self.ignoreEvtText = False
return
textEntered = event.GetString()
self.label.SetLabel("You selected" + self.combo.GetValue() + " from Combobox" + textEntered)
if textEntered:
self.ignoreEvtText = True
matching = [s for s in self.languages if textEntered in s]
self.combo.Set(matching)
self.combo.SetInsertionPoint(len(textEntered))
self.combo.SetValue(textEntered)
else:
self.combo.Set(self.languages)
self.combo.Popup()
app = wx.App()
Mywin(None, ‘ComboBox and Choice demo’)
app.MainLoop()