【wxpython】帮忙看看代码执行错误,找不到原因。。。。。。

syhhl123 2013-06-25 08:02:20
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
...全文
210 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
angel_su 2013-06-25
  • 打赏
  • 举报
回复
报错信息不是已经很白了,既然你不排序,去掉wx.LB_SORT式样吧。listbox适合选单用途,而你这个场景貌似是做显示输出,改用lstctrl较好...
syhhl123 2013-06-25
  • 打赏
  • 举报
回复
我把wx.LB_SORT删除掉后,程序就OK了。 但是我不明白这个样式对文件名有什么影响?
syhhl123 2013-06-25
  • 打赏
  • 举报
回复
构造函数里定义: self.result=wx.ListBox(panel,-1,size=(420,400),style=wx.LB_SINGLE|wx.LB_NEEDED_SB|wx.LB_SORT|wx.LB_HSCROLL)#定义列表框 调用的函数里: else: self.btnsearch.Enable(False) self.btnsearch.SetLabel("正在搜索...") 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("搜索")
panghuhu250 2013-06-25
  • 打赏
  • 举报
回复
程序不全,问题在self.result身上,但self.result是怎么构造的? \wx/ctrlsub.h(145) in wxItemContainer::InsertItems(): can't insert items in sorted control 前面的代码中对self.result排过序吗?

37,722

社区成员

发帖
与我相关
我的任务
社区描述
JavaScript,VBScript,AngleScript,ActionScript,Shell,Perl,Ruby,Lua,Tcl,Scala,MaxScript 等脚本语言交流。
社区管理员
  • 脚本语言(Perl/Python)社区
  • IT.BOB
加入社区
  • 近7日
  • 近30日
  • 至今

试试用AI创作助手写篇文章吧