wxpython 文件打开对话框
为什么这段wxpython代码会给我以下错误呢?
self.Bind(wx.EVT_MENU,self.onNewFile,self.New_File)
def onNewFile(self,evt):
wx.FileDialog(None,'Choose a file',os.getcwd(),"",wx.OPEN)
if dialog.ShowModal() == wx.ID_OK:
print dialog.GetPath()
dialog.Destroy()
其他设置菜单栏和创建项目的代码都在,但当执行这段代码时,我收到了以下错误:
Traceback (most recent call last):
File "C:\Python27\Front_End.py", line 52, in onNewFile
wx.FileDialog(None,'Choose a file',os.getcwd(),"",wx.OPEN)
File "C:\Python27\lib\site-packages\wx-2.8-msw-unicode\wx\_windows.py", line 2430, in __init__
_windows_.FileDialog_swiginit(self,_windows_.new_FileDialog(*args, **kwargs))
TypeError: String or Unicode type required
这是什么意思呢?
1 个回答
2
wx.FileDialog 的原型如下
__init__(self, parent, id, title, pos, size, style, name)
你可能漏掉了一个参数。我也稍微修改了一下你的代码,如下所示。
def onNewFile(self,evt):
dialog = wx.FileDialog(None,'Choose a file',os.getcwd(),"", "",wx.OPEN)
if dialog.ShowModal() == wx.ID_OK:
print dialog.GetPath()
dialog.Destroy()