Hiding command-line dialog in py2exe

限于喜欢 提交于 2019-11-28 01:40:51

问题


Hi When I compile my python script with py2exe, everything works well except a usless command-line dialog appears as well as my GUI. Any way to fix this? I have python 2.7 and my setup script looks like this:

from distutils.core import setup
import py2exe
setup(console=['Main.py'])  

Please help!


回答1:


Using setup(windows=['Main.py']) should remove the command line dialog and use Main.py as your console, instead.




回答2:


Rename your entry point python script extension from .py to .pyw and regenerate your exe.

Example: python -m py2exe.build_exe -b 0 my_script.pyw

(tested with Python 3.4.3 on Windows 8.1 x64)

Example: my_script.pyw

import ctypes
MessageBox = ctypes.windll.user32.MessageBoxW
MessageBox(None, 'Hello', 'Hello Window Title', 0)

You should not see a command prompt for this GUI application.



来源:https://stackoverflow.com/questions/11003040/hiding-command-line-dialog-in-py2exe

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!