Hide console window with Tkinter and cx_Freeze

后端 未结 7 1553
南方客
南方客 2020-12-03 03:52

I am using cx_freeze to freeze a tkinter app. When I run the exe I get a wonderfully USELESS console window along with my tkinter GUI.

I would like to remove

相关标签:
7条回答
  • 2020-12-03 04:29

    This question is very similar, but for wxPython and cx_Freeze. Fortunately, it turns out that the appearance of the console can be configured from the build script, rather than source code. Borrowing from the top two answers, the trick is setting the base variable in your cx_Freeze build script:

    import sys
    from cx_Freeze import setup, Executable
    
    base = None
    if (sys.platform == "win32"):
        base = "Win32GUI"    # Tells the build script to hide the console.
    
    # <The rest of your build script goes here.>
    

    Here is the relevant documentation (although it does not explicitly mention that base controls the console option).

    Also, just because it's interesting, an answer to a different question solves the issue of creating a GUI app with or without a console mode option, which I thought was very cool.

    0 讨论(0)
  • 2020-12-03 04:31

    For me using the option --base-name Win32GUI works. Here is an example:

    cxfreeze your_python_file.py --base-name Win32GUI --target-dir your_target_dir

    0 讨论(0)
  • 2020-12-03 04:34

    If using pyinstaller use pyinstaller-gui.py In Windows command line type

    python pyinstaller-gui.py

    This will first say "Please use just 'pyinstaller.py'. Gui is not maintained." Change the code l'il bit and you will be able to run this.

    It will show pop up a window to select your script and some checkboxex. Check on 'no console(windows only)

    That's it. You are done!

    Another option: use --noconsole option while building. i.e:

    python pyinstaller.py --noconsole yourscript.py

    0 讨论(0)
  • 2020-12-03 04:38

    Do exactly just like gary said, then:

    setup(name="ur package name",
             version="ur package version",
             description="as above",
             executables=[Executable("ur_script.py", base=base)]
    

    This will work cx_Freeze

    0 讨论(0)
  • 2020-12-03 04:43

    I'm assuming by "black window" you are referring to the terminal window. In order to disable this from popping up, save your file as a .pyw extension instead of .py

    0 讨论(0)
  • 2020-12-03 04:44

    I had the same problem today

    What i was using to compile my python programs was py2exe and the fix was very simple modify the setup file as shown below. My interface is written with Tkinter

    modify the "setup.py" py2exe script from:

    Old Python Code:

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

    New Python Code:

    from distutils.core import setup
    import py2exe
    setup(windows=['app.py'])
    

    After i did this and reran my setup script the application loaded and did not show the console window. The only thing with this is if you have your application sending print commands to the console window you will not see theme. I hope this helps.

    0 讨论(0)
提交回复
热议问题