【问题标题】:Windowed mode cannot run窗口模式无法运行
【发布时间】:2018-02-08 12:12:18
【问题描述】:

为什么 pyinstaller exe 不能在窗口模式下运行,但没有它就可以?我已经从 Linux 切换到 Windows 操作系统。以前从来没有遇到过任何问题,我该如何解决这个问题。

【问题讨论】:

    标签: python pyinstaller


    【解决方案1】:

    IHO 不使用窗口模式,而是在必要时抑制输出。

    如果你坚持使用它,Read这个。

    换句话说:

    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()
    

    我仍然不推荐这种方法。重定向或抑制标准输出要好得多。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-01-14
      • 2015-05-30
      • 2022-01-23
      • 1970-01-01
      • 2015-08-22
      • 1970-01-01
      • 1970-01-01
      • 2011-06-25
      相关资源
      最近更新 更多