Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

cx_Freeze help: is there a way to NOT make console open?

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

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

like image 979
Dalex Avatar asked Apr 15 '15 12:04

Dalex


People also ask

What is CX freeze?

cx_Freeze is a set of scripts and modules for freezing Python scripts into executables, in much the same way that py2exe and py2app do. Unlike these two tools, cx_Freeze is cross-platform and should work on any platform that Python itself works on. It supports Python 2.7 or higher (including Python 3).

What is Python error in main script?

According to some Windows users' reports, the problem “cx_Freeze: Python error in main script” may be caused by a poorly written Phyton application like PlayTV or Raptr. If you are in this case, you can try to uninstall PlayTV or Raptr to fix the cx_Freeze Python error. There are two ways to uninstall applications.


1 Answers

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
) 
like image 66
Dalex Avatar answered Sep 19 '22 13:09

Dalex