2017-02-04 43 views
0

我想基於輸入的輸入過濾組合框選項並分配新的選項列表。我可以分配的選項,但嘗試給它賦予的值給出以下錯誤: pydev調試器:開始(pid:6372) 回溯(最近調用最後一次): 文件「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的: '組合框' 對象沒有屬性 '的setValue'使用wxpython填充組合框中的過濾選項

我的代碼是如下:

!在/ usr/bin中/ Python的

20_combobox.py

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

你的問題是一個錯字。
使用SetValue()SetSelection()SetString()SetStringSelection()
您的代碼使用的setValue()代替SetValue()

+0

感謝Rolf..It工作得很好.. – Ganesh