Hide the console of an .exe file created with PyInstaller in Tkinter

PyInstaller is used with Tkinter to package the Python file into a stand-alone executable file in .exe format. The .exe file is a single file application or software which can be run on a Windows platform. This exe file contains all dependencies, and assets used in the Python file which helps both the nontechnical and technical users of the application to use the application without the need to install or copy files in the computer.

The exe file converted using PyInstaller when opened opens with a console by default. This makes both the application file and the console open always. In this article, we will discuss hiding the console when a .exe file is created using PyInstaller easily.

How to Hide the console of a .exe file created with PyInstaller in Tkinter?

Step 1: Create a Simple Tkinter Python file

Python
# importing tkinter
import tkinter as tk


# GUI
root = tk.Tk()
root.title("w3wiki")
root.geometry("280x100")
root.config(bg="green")
tk.Label(root, text="Welcome to GFG!", fg="white",
         bg="green", font=("Arial", 16, "bold")).pack(pady=15)
root.mainloop()

Step 2: Open Command Prompt

Open command prompt by clicking the ‘Start’ icon in your windows lower left most corner, and type ‘cmd’. Click ‘Open’ under ‘Command prompt’.

Step 3: Navigate to the project folder containing the Python file

Navigate to the folder containing the Tkinter Python file in your computer using the command ‘cd’ followed by the folder name.

Navigating inside the folder containing the python Tkinter file to conver

Step 4: Type the command in the command prompt to convert to exe file along with –noconsole

On navigating inside the folder containing the Tkinter python file, type the below command. To hide the console of the .exe file, use –noconsole in the command. This denotes that the executable file which is going to be created will not open with a console.

Here the python file name is sample.py. Hence the command is as below:

python -m PyInstaller sample.py --onefile --noconsole

The command prompt screen is as below,

Type the command to convert to exe with –noconsole to hide the console opening with exe file

Step 5: Press ‘Enter’ key in the keyboard to convert the python file to executable file

Now press ‘Enter’ key in your keyboard. The command executes in the command prompt and the conversion process started. It takes 1 to 2 minutes.

Step 6: The conversion process is completed

Now the executable file is converted and ready to be opened.

Command executed and python file is converted to executable file successfully

In your project folder, open the ‘dist’ folder to view the created executable file.

Step 7: Double click on the .exe file to open it

It opens as a single window application only. No console is opened along with it.

The exe file opened without console


Conclusion

In this article, we have discussed about PyInstaller and the steps to hide the console of an .exe file using PyInstaller.