>> The "package require Tk" will crash (just as wish will crash) is
>> there is "no windowing system" -- typically on a Linux/Unix system
>> in a non-GUI environment, like a cron job or slogin without X11
>> forwarding, etc.
>
> When I get the option to start with GUI it would be nice to check for
> a windowing system. In this case it is only for Linux, so it is
> ?simple?. But for if I make a more complex variant:
> - Windows always has a windowing system?
> - With unix/linux I only have to check for the DISPLAY environment
> variable?
Actually, "package require Tk" does not "crash", it returns an error if
no windowing system is found.
However, if that error is not caught by the script, then the default
error handler aborts the script at the point of the error and prints
out some error info and a stack trace.
So to detect if a windowing system is available, just [catch] the error
from package require Tk and take appropriate action:
if {[catch {package require Tk}]} {
# No windowing system - perform CLI duties
} else {
# Windowing system available - initalize GUI
}
The above should be portable across Linux/Windows/MacOS and likely
the BSD's.