Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
247 views
in Technique[技术] by (71.8m points)

python - Windowed mode cannot run

Why does pyinstaller exe not run in windowed mode but fine without it? I have changed over to a windows OS from Linux. Never had any issue before hand, how do I correct this.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

IHO don’t use windowed mode, rather suppress output if you have to.

If you insist on using it, Read this.

In other words:

import sys
import subprocess
from PyQt4 import QtGui

def verify_license():
    tmp_file = '.license_output'

    try:
        with open(tmp_file, 'w+') as file_obj:
            proc = subprocess.Popen(['echo', 'hi'], shell=True,
                                    stdout=file_obj, stderr=subprocess.STDOUT,
                                    stdin=subprocess.PIPE)
            ret = proc.wait()

        if ret != 0:
            sys.exit(-1)

        with open(tmp_file, 'r') as file_obj:
            output = file_obj.read()

    except Exception as err:
        sys.exit(-1)

    if 'hi' not in output:
        raise Exception('bad news: output was %s' % (output))


def main():
    app = QtGui.QApplication(sys.argv)

    w = QtGui.QWidget()
    w.resize(250, 150)
    w.move(300, 300)
    w.setWindowTitle('Simple')
    w.show()

    sys.exit(app.exec_())


if __name__ == '__main__':
    verify_license()
    main()

I still do not recommend this approach however. Redirect or suppress stdout is much better.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...