Determining Presence Of GUI Support

Martin v. Loewis martin at v.loewis.de
Sat Nov 9 02:27:38 EST 2002


Tim Daneliuk <tundra at tundraware.com> writes:

> Is there a portable method of determining whether the current runtime
> environment supports a GUI or text-based interface?  I would like to
> write a single program which autosenses the presentation environment
> and works accordingly.

I'm not quite sure what you mean by "environment" and "supports GUI".
The environment may support a GUI, but you may not have the libraries,
or you may have a GUI, have the libraries, but your program may not be
prepared to use these libraries, and so on.

To verify whether you have Tk libraries, import Tkinter. If that gives
an ImportError, you don't have Tk libraries. Then, create an
Tkinter.Tk instance. If that gives a Tkinter.TclError, you cannot use
Tk as a GUI.

For other libraries, similar procedures apply.

HTH,
Martin




More information about the Python-list mailing list