wxPython文件对话框错误:缺少"|" 在通配符字符串中!

2 python wxpython

我在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!
Run Code Online (Sandbox Code Playgroud)

当对话框打开时,一切看起来都很好.有任何想法吗?

编辑:输入太快,忘了包含有问题的通配符字符串!抱歉...

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()
...
Run Code Online (Sandbox Code Playgroud)

Ned*_*der 7

通配符字符串具有奇怪的格式,从Win32借用:

Desc1|wildcard1|Desc2|wildcard2 ...
Run Code Online (Sandbox Code Playgroud)

应该有奇数个管道,以便管道分离的部分形成对,描述和通配符.例如:

Spreadsheet (*.xls)|*.xls|Plain-old text (*.txt)|*.txt|Random noise|*.dat
Run Code Online (Sandbox Code Playgroud)

请注意,描述通常包含一个括号通配符,仅用于显示目的.

您的问题是尾随管道符号.去掉它.