有没有办法不打开控制台

有没有办法不打开控制台

本文介绍了cx_Freeze帮助:有没有办法不打开控制台?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将python游戏(由pygame制作)转换为Windows的exe文件,并且确实使用cx_Freeze。那里没有问题。

问题是,当我启动myGame.exe时,它会打开常规的Pygame窗口和一个控制台窗口(我不想要)。

I am trying to convert a python game (made with pygame) into a exe file for windows, and I did using cx_Freeze. No problems there.
The thing is that when I launch myGame.exe, it opens the normal Pygame window and a console window(which I do not want).

是否可以删除控制台窗口?我阅读了大部分文档,但实际上什么也没看到(除了基本版,但我没有得到什么。)

Is there a way to remove the console window? I read most of the documentation, but I saw nothing really (except base, but I don't get what that is).

BTW,这是我的安装文件:

BTW, here is my setup file:

import cx_Freeze

exe = [cx_Freeze.Executable("myGame.py")]

cx_Freeze.setup(
    name = "GameName",
    version = "1.0",
    options = {"build_exe": {"packages": ["pygame", "random", "ConfigParser", "sys"], "include_files": [
    "images", "settings.ini", "arialbd.ttf"]}},
    executables = exe
)

以下是我启动exe时的屏幕截图:

Here's a screen shot of what happens when I launch the exe:

推荐答案

所以出了问题,是setup.py文件缺少参数了。

您需要添加的是 base = Win32GUI 声明在启动应用程序时不需要控制台窗口。

这是代码:

So what was wrong, was that the setup.py file was missing a parameter.
What you need to add is base = "Win32GUI" to declare that you do not need a console window upon launch of the application.
Here's the code:

import cx_Freeze

exe = [cx_Freeze.Executable("myGame.py", base = "Win32GUI")] # <-- HERE

cx_Freeze.setup(
    name = "GameName",
    version = "1.0",
    options = {"build_exe": {"packages": ["pygame", "random", "ConfigParser", "sys"],
        "include_files": ["images", "settings.ini", "arialbd.ttf"]}},
    executables = exe
)

这篇关于cx_Freeze帮助:有没有办法不打开控制台?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-31 09:58