wxpython文件打开对话框

时间:2012-02-09 03:04:08

标签: c++ python user-interface wxpython wsgi

为什么这个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 个答案:

答案 0 :(得分: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()