どのOSを使用していますか?どのパイソン?どのwxPython? これは、私のチュートリアルの 1 つのコードによく似ており、うまく機能しました。私は先に進み、実際にそのチュートリアルから簡素化された実行可能な例を書きました:
import os
import wx
########################################################################
class MyForm(wx.Frame):
#----------------------------------------------------------------------
def __init__(self):
wx.Frame.__init__(self, None, wx.ID_ANY,
"File and Folder Dialogs Tutorial")
panel = wx.Panel(self, wx.ID_ANY)
self.currentDirectory = os.getcwd()
dirDlgBtn = wx.Button(panel, label="Show DirDialog")
dirDlgBtn.Bind(wx.EVT_BUTTON, self.onDir)
#----------------------------------------------------------------------
def onDir(self, event):
"""
Show the DirDialog and print the user's choice to stdout
"""
dlg = wx.DirDialog(self, "Choose a directory:",
style=wx.DD_DEFAULT_STYLE
#| wx.DD_DIR_MUST_EXIST
#| wx.DD_CHANGE_DIR
)
if dlg.ShowModal() == wx.ID_OK:
print "You chose %s" % dlg.GetPath()
dlg.Destroy()
#----------------------------------------------------------------------
# Run the program
if __name__ == "__main__":
app = wx.App(False)
frame = MyForm()
frame.Show()
app.MainLoop()
このコードは、Python 2.6.6 と wxPython 2.8.12.1 を使用して Windows 7 で実行しました。3 つの異なるディレクトリを選択すると、3 つの異なるパスがすべて出力されました。