cx_Freeze Exe Application closes as soon as opens

大憨熊 提交于 2019-12-04 09:41:32

I copied your setup script and tested it with one of my own Pygame projects. It didn't work for me either at first, so I investigated the problem and found a bug on Bitbucket: https://bitbucket.org/anthony_tuininga/cx_freeze/issues/211/if-name-main-doesnt-work-in

Apparently there is a bug, specifically with cx-Freeze version 5.0, that the line if __name__ == "__main__": will not work. But when I replaced it with if __name__.endswith('__main__'): as suggested in the bug report, then my Pygame app worked with cx-Freeze, so this fixed the problem for me.

In addition, I would suggest adding the keyword argument base="Win32Gui" to cx_Freeze.Executable, so that the console window doesn't show up behind the Pygame window, unless if you want it. Also, Tkinter is completely unnecessary for a Pygame app, so you can add "excludes": ["Tkinter"] (or lowercase tkinter in Python 3) to the options dict and get rid of the first three lines of your script.

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