py2exe: Allow a console window to be either shown or hidden with a sys.argv

100 views Asked by At

I have a python program using PySide. When run normally, it opens up a PySide GUI, but when run with some flags in the command line, it spits some things out in the console window.

I'd like to retain this dual functionality, but it seems with py2exe you have to choose whether to have a console window or not when compiling, with no option for choosing during program execution.

Is what I want to do possible with py2exe, or even with some other python "compiler?"

1

There are 1 answers

2
Zenadix On

This is not a py2exe limitation, but a Windows limitation. On Windows, applications are compiled either as Console Applications or GUI Applications. The difference is that Console Applications always open a console window, whilst GUI Applications never do.

As far as I can tell, it's not possible to have an application with dual functionality. As a workaround, I suggest that you simply compile two executables: one for console use and one for GUI use.