Simple and Minimal File Selection GUI with Standard Python

I have a simple script which parses an excel file and does some data analysis on it’s contents and reports it as a html output. I don’t need a UI, but right now I’m prompting the user for the file to parse using raw_input which is very inconvenient. So needed to find a quick and easy way to present a file selection dialog to the user with which they can select the excel file.

My first choice was wx. But then realised i needed something thats part of standard python and that landed me to this page File Tkinter dialogs (Python recipe)

Here’s the super convenient and simple way to get a minimal file selection GUI from standard python modules.

import Tkinter,tkFileDialog
root = Tkinter.Tk()
root.withdraw()
filename = tkFileDialog.askopenfile(parent=root,mode='r',filetypes=[(“Excel file”,”*.xls”)],title='Choose an excel file')
if filename != None:
    print “This excel file has been selected”, file

Thanks internet!!

And here’s a good presentation on Tkinter titled “Tkinter Does Not Suck”. I agree…

One thought on “Simple and Minimal File Selection GUI with Standard Python

  1. Pingback: Matplotlib Embedded with Tkinter. | SukhbinderSingh.com

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s