[Tutor] Launching a file browser

Jeff Shannon jeffshannon at gmail.com
Sat Apr 2 02:12:21 CEST 2005


On Mar 31, 2005 2:14 PM, Mike Hall <michael.hall at critterpixstudios.com> wrote:
> 
> >> It's been too long since I used Python on MacOSX, but IIRC you can't
> >> just run a Python GUI program from the shell. Or something like
> >> that...you should ask this one on the python-mac SIG mailing list:
> >> http://www.python.org/sigs/pythonmac-sig/
> >>
> >> Kent
> 
> I'm unclear on why a command like webbrowser.open() will comfortably
> launch your default web browser (in my case Safari), but something as
> ubiquitous to an OS as a file browser has special needs to launch.

At the OS level, these two actions are *completely* different.  The
webbrowser module launches an entirely separate program in its own
independent process, where the "file browser" is opening a standard
dialog inside of the current process and dependent upon the current
process' message loop.  (AFAIK, every GUI environment uses some sort
of message/event loop...)

I don't know Macs, but on Windows, the closest "file browser" parallel
to what the webbrowser module is doing would be
os.system("explorer.exe"), which launches a separate program in an
independent process.  However, if you're trying to get the results of
the file selection back into your own app, you need to do the file
browsing within your own process (or explicitly use some form of
inter-process communication).  In order to use a GUI file-browsing
dialog, you need to follow all the rules for a GUI program.

Jeff Shannon


More information about the Tutor mailing list