Code for creating simple dir and file selectors using functions
that are built in to python. The python 2.5 docs are missing info
on the methods in tkFileDialog.

This code is a copy of the code from:

http://code.activestate.com/recipes/438123-file-tkinter-dialogs/

with the suggestions in the comments added. The reason I copied it here
is to keep all the snippets I use in one place.

All credit goes to the original author: Sébastien Sauvage


# ======== Select a directory:

import Tkinter, tkFileDialog

root = Tkinter.Tk()
root.withdraw()
dirname = tkFileDialog.askdirectory(parent=root,initialdir="/",title='Please select a directory')
if len(dirname ) > 0:
print "You chose %s" % dirname


# ======== Select a file for opening:
import Tkinter,tkFileDialog

root = Tkinter.Tk()
root.withdraw()
file = tkFileDialog.askopenfile(parent=root,mode='rb',title='Choose a file')
if file != None:
data = file.read()
file.close()
print "I got %d bytes from this file." % len(data)


# ======== "Save as" dialog:
import Tkinter,tkFileDialog

myFormats = [
('Windows Bitmap','*.bmp'),
('Portable Network Graphics','*.png'),
('JPEG / JFIF','*.jpg'),
('CompuServer GIF','*.gif'),
]

root = Tkinter.Tk()
root.withdraw()
fileName = tkFileDialog.asksaveasfilename(parent=root,filetypes=myFormats ,title="Save the image as...")
if len(fileName ) > 0:
print "Now saving under %s" % nomFichier

Read more: http://feeds.dzone.com/~r/dzone/snippets/~3/1cYdOoDD69w/12085