使用wxpython在组合框中填充筛选的选项

使用wxpython在组合框中填充筛选的选项,wxpython,Wxpython,我试图根据输入的输入筛选组合框选项,并分配新的选项列表。我可以分配选项,但尝试分配它给出的值,错误如下: pydev调试器:正在启动(pid:6372) 回溯(最近一次呼叫最后一次): 文件“C:\WORK\ATEWorkSpace\TRY\u ERROR\combobox\u working.py”,第31行,文本\u return self.st.setValue(文本输入) AttributeError:“ComboBox”对象没有属性“setValue” 回溯(最近一次呼叫最后一次):

我试图根据输入的输入筛选组合框选项,并分配新的选项列表。我可以分配选项,但尝试分配它给出的值,错误如下: pydev调试器:正在启动(pid:6372) 回溯(最近一次呼叫最后一次): 文件“C:\WORK\ATEWorkSpace\TRY\u ERROR\combobox\u working.py”,第31行,文本\u return self.st.setValue(文本输入) AttributeError:“ComboBox”对象没有属性“setValue” 回溯(最近一次呼叫最后一次): 文件“C:\WORK\ATEWorkSpace\TRY\u ERROR\combobox\u working.py”,第31行,文本\u return self.st.setValue(文本输入) AttributeError:“ComboBox”对象没有属性“setValue”

我的代码如下:

!/usr/bin/python 20_combobox.py
有谁能告诉我代码有什么问题吗?

你的问题是打字错误。
使用
SetValue()
SetSelection()
SetString()
SetStringSelection()
您的代码正在使用
setValue()
而不是
setValue()

import wx
import wx.lib.inspection

class MyFrame(wx.Frame):
    def __init__(self, *args, **kwargs):
        wx.Frame.__init__(self, *args, **kwargs)

        self.choices = ['grandmother', 'grandfather', 'cousin', 'aunt', 'uncle', 'grandson', 'granddaughter']
        for relative in ['mother', 'father', 'sister', 'brother', 'daughter', 'son']:
            self.choices.extend(self.derivedRelatives(relative))
        self.st = wx.ComboBox(self, -1, choices = self.choices, style=wx.CB_SORT)

        self.st.Bind(wx.EVT_TEXT, self.text_return)
        self.ignoreEvtText = False

    def text_return(self, event):
        if self.ignoreEvtText:
            self.ignoreEvtText = False
            return
        filteredList=[]
        textEntered=event.GetString()   

        if textEntered:
            matching = [s for s in self.choices if textEntered in s]
            self.st.Set(matching)
            self.ignoreEvtText = True 
            self.st.setValue(textEntered)
        else:
            self.st.Set(self.choices)        

    def derivedRelatives(self, relative):
        return [relative, 'step' + relative, relative + '-in-law']

class MyApp(wx.App):
    def OnInit(self):
        frame = MyFrame(None, -1, '20_combobox.py')
        frame.Show()
        self.SetTopWindow(frame)
        return 1

if __name__ == "__main__":
    app = MyApp(0)
    app.MainLoop()