wxpython文件打开对话框

wxpython file opening dialog

本文关键字:打开对话框 文件 wxpython      更新时间:2023-10-16

为什么这个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:Python27Front_End.py", line 52, in onNewFile
    wx.FileDialog(None,'Choose a file',os.getcwd(),"",wx.OPEN)
  File "C:Python27libsite-packageswx-2.8-msw-unicodewx_windows.py", line 2430, in __init__
    _windows_.FileDialog_swiginit(self,_windows_.new_FileDialog(*args, **kwargs))
TypeError: String or Unicode type required

这是什么意思?

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()