0

我想知道如何在 openfiledialog 打开时更改目录。我想将其设置为特定目录。

def OnOpen(self,event):
        """Open a file"""
        openFileDialog = wx.FileDialog(self,"Open log file","","","Log files (*.log)|*.log",wx.FD_OPEN | wx.FD_FILE_MUST_EXIST |wx.FD_CHANGE_DIR)

        if openFileDialog.ShowModal() == wx.ID_CANCEL:
            return

        input_stream = wx.FileInputStream(openFileDialog.GetPath())

        if not input_stream.IsOk():
            wx.LogError("Cannot open file '%s'."%openFileDialog.GetPath())
            return 

我看到了诸如 setdirectory 之类的函数。我不知道在哪里应用该参数。

4

1 回答 1

0

FileDialog 您应该在创建之后设置默认目录,但在显示之前

def OnOpen(self,event):
        """Open a file"""
        openFileDialog = wx.FileDialog(self,"Open log file","","","Log files (*.log)|*.log",wx.FD_OPEN | wx.FD_FILE_MUST_EXIST |wx.FD_CHANGE_DIR)

        openFileDialog.SetDirectory(some_dir)

        if openFileDialog.ShowModal() == wx.ID_CANCEL:
            return
        ...
于 2013-11-09T06:48:18.247 回答