9

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/hide this useless black window.

I've seen threads that suggest the following:

root = tkinter.Tk()
root.withdraw()

The above code does the opposite of what I want. It hides my GUI, while the useless black window remains. I would like it to be the other way around.

gary
  • 4,227
  • 3
  • 31
  • 58
Rhys
  • 4,926
  • 14
  • 41
  • 64

7 Answers7

14

I remember reading somewhere that on Windows if you specify your file extension as .pyw, it will launch with pythonw.exe (without a console window). Does that work for you?

Noufal Ibrahim
  • 71,383
  • 13
  • 135
  • 169
11

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.

Community
  • 1
  • 1
gary
  • 4,227
  • 3
  • 31
  • 58
  • 1
    This answer works, however you must add base=base in executables= in your setup.py file. See VICTOR answer below for an example. – Phoenix Jul 03 '14 at 08:42
5

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

IcyFlame
  • 5,059
  • 21
  • 50
  • 74
Victor
  • 81
  • 1
  • 2
2

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

2

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

Tom Pohl
  • 2,711
  • 3
  • 27
  • 34
2

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.

user3885927
  • 3,363
  • 2
  • 22
  • 42
Doomloard
  • 43
  • 8
1

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