tags:

views:

35

answers:

1

I'm using OS X. I'm double clicking my script to run it from Finder. This script imports and runs the function below.

I'd like the script to present a Tkinter open file dialog and return a list of files selected.

Here's what I have so far:

def open_files(starting_dir):
    """Returns list of filenames+paths given starting dir"""
    import Tkinter
    import tkFileDialog

    root = Tkinter.Tk()
    root.withdraw()  # Hide root window
    filenames = tkFileDialog.askopenfilenames(parent=root,initialdir=starting_dir)
    return list(filenames)

I double click the script, terminal opens, the Tkinter file dialog opens. The problem is that the file dialog is behind the terminal.

Is there a way to suppress the terminal or ensure the file dialog ends up on top?

Thanks, Wes

A: 

Try the focus_set method. For more, see the Dialog Windows page in PythonWare's An Introduction to Tkinter.

GreenMatt
Thank you. I read it over. I'm not sure how I can use the set_focus() method on the built in TK file dialog window?
Wes