我在Windows7上,使用Python 2.6和wxPython 2.8.10.1。我试图让这个“打开文件”对话框正常工作,但遇到了一个奇怪的错误。对我来说,这看起来像是一个有效的通配符字符串,但每当我选择一个文件并单击“文件”对话框上的“确定”时,我都会得到以下信息:
Traceback (most recent call last):
File "D:\Projects\python\wxTest.py", line 92, in OnOpen
self.__DoOpen()
File "D:\Projects\python\wxTest.py", line 101, in __DoOpen
if open_dlg.ShowModal() == wx.ID_OK:
File "C:\Python26\lib\site-packages\wx-2.8-msw-unicode\wx\_windows.py", line 711, in ShowModal
return _windows_.Dialog_ShowModal(*args, **kwargs)
wx._core.PyAssertionError: C++ assertion "wxAssertFailure" failed at
..\..\src\common\filefn.cpp(1746) in wxParseCommonDialogsFilter():
missing '|' in the wildcard string!
当对话框打开时,一切看起来都很好。有任何想法吗?
编辑:输入太快,忘记包含有问题的通配符字符串!对不起...
wcd = "All files(*.*)|*.*|Text files (*.txt)|*.txt|"
open_dlg = wx.FileDialog(self, message='Choose a file', defaultDir=directory, defaultFile='', style=wx.OPEN | wx.CHANGE_DIR)
open_dlg.SetWildcard(wcd)
if open_dlg.ShowModal() == wx.ID_OK:
path = open_dlg.GetPath()
...
通配符字符串有一种奇怪的格式,借用自 Win32:
Desc1|wildcard1|Desc2|wildcard2 ...
管道的数量应该是奇数,以便管道分隔的部分形成对、描述和通配符。例如:
Spreadsheet (*.xls)|*.xls|Plain-old text (*.txt)|*.txt|Random noise|*.dat
请注意,描述通常包含括号通配符,仅用于显示目的。
您的问题是尾随管道符号。去掉它。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)