Based on the answer in this post, you can get this behaviour in a python script as follows:
import subprocess
output = subprocess.check_output(["xset", "q"], stderr=subprocess.STDOUT)
print(output)
This script will printout the results of the xset q
command if an X server is available. If I damage my $DISPLAY
variable then it fails with a python exception:
subprocess.CalledProcessError: Command '['xset', 'q']' returned non-zero exit status 1
So you could put this in a try:
and if it fails, you know something is up with displaying the X window. It might be due to a bad or missing DISPLAY variable, or something else but it should indicate that attempting to show the wx window is likely to fail.