Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Hide console window with Tkinter and cx_Freeze

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.

like image 977
Rhys Avatar asked Apr 02 '11 14:04

Rhys


3 Answers

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.

like image 144
gary Avatar answered Nov 11 '22 19:11

gary


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?

like image 14
Noufal Ibrahim Avatar answered Nov 11 '22 19:11

Noufal Ibrahim


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

like image 5
Victor Avatar answered Nov 11 '22 18:11

Victor