我在Windows7上,使用Python 2.6和wxPython 2.8.10.1。我试图让这个打开文件对话框工作,但运行到一个奇怪的错误。这看起来像一个有效的通配符字符串给我,但每当我选择一个文件,然后单击“确定”在文件对话框中,我得到这个:wxPython文件对话框错误:缺少“|”在通配符字符串中!
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()
...
你能告诉我们你使用的通配符字符串吗? – 2009-12-23 02:58:07