Selecting a file in a directory

Alf P. Steinbach alfps at start.no
Sat Feb 13 20:28:13 EST 2010


* vsoler:
> Hi,
> 
> My python script needs to work with a .txt file in a directory. I
> would like to give the user the possibility to choose the file he
> needs to work on in as much the same way as I open a .xls file in
> Excel, that is, I want to make appear the "Windows'" window and let
> the user choose.
> 
> I think this should be quite straightforward.
> 
> How should I proceed?

At least in Windows one easy way is to delegate that responsibility to the 
Windows shell. When a user drags a file onto your script, your script is run 
with the path to that dragged file as argument. Or it can even be multiple files.

Otherwise, tkinter has, as I recall, a standard file chooser dialog.

These "standard" dialogs are generally called "common dialogs".

Just google for tkinter and suitable words.



Cheers & hth.,

- Alf



More information about the Python-list mailing list