The referenced threads do appear to accomplish what you ask for. However, I consider it a bad idea to mix GUI with command-line interface in the same script. It may confuse your users more than help them. The somewhat non-standard code will be a maintenance problem for the life of your script.