Tom
Tom

Reputation: 21

How to Hide the console of an .exe file when run the "pyw" file?

I am making a welcome message and I want it to run underground and when I run underground it the computer will pop up the terminal like this: "C:\WINDOWS\system32\cmd.exe" I press "X" to close it and the program will stop and break. I do not know how to hide this.

Here is my code:

import subprocess
import pyautogui
import time
import pandas as pd
import datetime
import os
import pyttsx3
from tkinter import *

user = "Stark Nguyen" #your name
# Robot speech
# Jarvis_brain = speak
# Jarvis_mouth = engine
assistant= "Jarvis" # Iron man Fan
Jarvis_mouth = pyttsx3.init()
Jarvis_mouth.setProperty("rate", 140)
voices = Jarvis_mouth.getProperty("voices")
Jarvis_mouth.setProperty("voice", voices[1].id)

def Jarvis_brain(audio):
    print("Jarvis: " + audio)
    Jarvis_mouth.say(audio)
    Jarvis_mouth.runAndWait()

# Welcome message
def greet():
    hour=datetime.datetime.now().hour
    if hour>=0 and hour<12:
        Jarvis_brain("Start the system, your AI personal assistant Jarvis")
        Jarvis_brain(f"Hello, Good Morning {user}")
        print("Hello,Good Morning")
    elif hour>=12 and hour<18:
        Jarvis_brain("Start the system, your AI personal assistant Jarvis")
        Jarvis_brain(f"Hello, Good Afternoon {user}")
        print("Hello, Good Afternoon")
    else:
        Jarvis_brain("Start the system, your AI personal assistant Jarvis")
        Jarvis_brain(f"Hello, Good Evening {user}")
        print("Hello,Good Evening")
greet()        

os.system("python op1.py")

Upvotes: 0

Views: 124

Answers (1)

RichAspden
RichAspden

Reputation: 76

If you save it as a .pyw file, like you say in your title, you'll hide the console. Downside of this, is that your print() calls won't print anywhere, since they print to the console.

Upvotes: 1

Related Questions