Dialogs in wxPython - wxDirDialog
(Page 5 of 6 )
If your application requires the user to select a directory for something, consider using wxDirDialog. It allows the user to pick a directory from a tree:
from wxPython.wx import *
application = wxPySimpleApp()
# Create the dialog
dialog = wxDirDialog ( None, message = 'Pick a directory.' )
# Show the dialog and get user input
if dialog.ShowModal() == wxID_OK:
print 'Directory:', dialog.GetPath()
# The user cancelled
else:
print 'No directory.'
# Get rid of the dialog
dialog.Destroy()
It is also possible to allow the user to create a new directory from within the dialog by passing the wxDD_NEW_DIR_BUTTON style:
from wxPython.wx import *
application = wxPySimpleApp()
dialog = wxDirDialog ( None, message = 'Pick a directory.', style = wxDD_NEW_DIR_BUTTON )
if dialog.ShowModal() == wxID_OK:
print 'Directory:', dialog.GetPath()
else:
print 'No directory.'
dialog.Destroy()
Next: wxFileDialog >>
More Python Articles
More By Peyton McCullough