我正在尝试根据输入的输入过滤组合框选项并分配新的选择列表。选择我能够分配,但尝试分配它给出以下错误的值: pydev调试器:启动(pid:6372) Traceback(最近一次调用最后一次): 文本“C:\ WORK \ ATEWorkSpace \ TRY_ERROR \ combobox_working.py”,第31行,在text_return中 self.st.setValue(textEntered) AttributeError:'ComboBox'对象没有属性'setValue' Traceback(最近一次调用最后一次): 文本“C:\ WORK \ ATEWorkSpace \ TRY_ERROR \ combobox_working.py”,第31行,在text_return中 self.st.setValue(textEntered) AttributeError:'ComboBox'对象没有属性'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()
请有人建议我代码有什么问题吗?
答案 0 :(得分:0)
你的问题是一个错字
使用SetValue()
,SetSelection()
,SetString()
,SetStringSelection()
您的代码使用setValue()
代替SetValue()