Dialogs in wxPython - ImageDialog
(Page 4 of 6 )
The ImageDialog is a very nice dialog. It displays the images in a given directory. It's very simple to use:
from wxPython.wx import *
# Import the required module
from wxPython.lib import imagebrowser
application = wxPySimpleApp()
# Create the dialog
dialog = imagebrowser.ImageDialog ( None )
# Show the dialog
dialog.ShowModal()
# Destroy the dialog
dialog.Destroy()
Of course, we'll need to retrieve the file name of the image that the user specifies. This is easily done:
from wxPython.wx import *
from wxPython.lib import imagebrowser
application = wxPySimpleApp()
dialog = imagebrowser.ImageDialog ( None )
# Display the file name if the user selected one
if dialog.ShowModal() == wxID_OK:
print 'You picked:', dialog.GetFile()
# Otherwise, yell and scream at the user for cancelling
else:
print 'You did not select an image!'
dialog.Destroy()
If we need to set a directory other than the current directory, it's possible to do so by passing a second argument:
from wxPython.wx import *
from wxPython.lib import imagebrowser
application = wxPySimpleApp()
# Specify a directory
dialog = imagebrowser.ImageDialog ( None, 'C:\' )
if dialog.ShowModal() == wxID_OK:
print 'You picked:', dialog.GetFile()
else:
print 'You did not select an image!'
dialog.Destroy()
Next: wxDirDialog >>
More Python Articles
More By Peyton McCullough