views:

391

answers:

5

I was wondering if there is something similar to Java's JFileChooser for Python?

JFileChooser is a graphical front end to choose a file.

Preferably something that is already with Python..maybe with Tkinter.

Thanks for your help :)

+1  A: 

That would depend on your windowing toolkit. wxWidgets provides the wxFileDialog.

Hank Gay
Thanks Hank, I'll look into it. :)
Casey
+3  A: 

wxPython (www.wxpython.org) provides the wx.FileDialog class which will give you a native file selection dialog on any of the supported platforms (Mac, Linux or Windows).

Wayne Koorts
Thanks WAyne. Think Hank beat ya to it ;)
Casey
A: 

Maybe you would like to take a look at Jython.

hyperboreean
+3  A: 

Easiest way I ever found to do this (using PyGTK and Kiwi):

from kiwi.ui.dialogs import open as open_dialog

chosen_path = open_dialog('Select a file', folder='/start/folder')

if chosen_path is not None:
    # do something ...
Ali A
looks good. thanks for the tip ;)
Casey
+3  A: 

For something that doesn't require wxPython and sticks with the standard Python libs, you can use the tkFileDialog.askopenfilename() method:

#!/usr/bin/python

from Tkinter import *
from tkFileDialog import askopenfilename

root = Tk()
root.withdraw()
print askopenfilename()
Jay
+1 for an actual example
Ali A
@Casey - you're welcome, glad it was helpful!
Jay