Determining Presence Of GUI Support

Grant Edwards grante at visi.com
Sat Nov 9 12:06:41 EST 2002


In article <mailman.1036856112.6119.python-list at python.org>, Gerhard Häring wrote:
> * Tim Daneliuk <tundra at tundraware.com> [2002-11-09 06:40 +0000]:
>> 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.
> 
> You can obtain wether or not you're running under X11 by checking for
> the existence of the "DISPLAY" environment variable:
> 
>>>> import os
>>>> "DISPLAY" in os.environ
> 1

Or, you could just try to initialize your GUI, and catch whatever exception
is raised when there's no GUI support in the OS environment.

-- 
Grant Edwards                   grante             Yow!  The Korean War must
                                  at               have been fun.
                               visi.com            



More information about the Python-list mailing list