【wxpython】帮忙看看代码执行错误,找不到原因。。。。。。
self.matches=[]
self.result.Clear()#清空列表框
self.find(self.filename.GetValue(),self.dirpath.GetValue())#查找文件
if len(self.matches)==0:#判断是否找到了文件
lstmp=["没有符合条件的记录!"]
else:
lstmp=["共查找到"+str(len(self.matches))+"条符合条件的记录:"]
self.result.InsertItems(lstmp,0)
self.result.InsertItems(self.matches,1)
self.btnsearch.Enable(True)
self.btnsearch.SetLabel("搜索")
def find(self,pattern,startdir=os.curdir):
for (thisdir, subdirs,fileshere) in os.walk(startdir):
for filename in fileshere:
if fnmatch.fnmatch(filename, pattern):
fullpatch = os.path.join(thisdir, filename)
self.matches.append(fullpatch)
为什么提示self.result.InsertItems(lstmp,0)这句有问题?帮忙看看
> "C:\Python27\python.exe" "D:\program_py\search\FileSearch.py"
Traceback (most recent call last):
File "D:\program_py\search\FileSearch.py", line 63, in OnSearch
self.result.InsertItems(lstmp,0)
File "C:\Python27\lib\site-packages\wx-2.9.4-msw\wx\_controls.py", line 1178, in InsertItems
return _controls_.ListBox_InsertItems(*args, **kwargs)
wx._core.PyAssertionError: C++ assertion "!IsSorted()" failed at C:\BUILD\wxPython-src-2.9.4.0\include\wx/ctrlsub.h(145) in wxItemContainer::InsertItems(): can't insert items in sorted control
wxPython
[解决办法]
报错信息不是已经很白了,既然你不排序,去掉wx.LB_SORT式样吧。listbox适合选单用途,而你这个场景貌似是做显示输出,改用lstctrl较好...