So I created a program with PySimpleGUI and then made .exe file from it with Pyinstaller. Here is my command:
pyinstaller --hidden-import=pyttsx3.drivers --hidden-import=pyttsx3.drivers.dummy --hidden-import=pyttsx3.drivers.espeak --hidden-import=pyttsx3.drivers.nsss --hidden-import=pyttsx3.drivers.sapi5 -F -w -i "C:\Users\icons\logo.ico" prog.py
-F for one file prog
-w for windowed app (without command prompt)
-i for icon
By the way when I make it without '-w' it works perfectly, but I want app with no cmd
My code:
layout = [
[sg.Text('', size=(30, 2)), sg.Text('Press "Start" button', size=(55, 12), key='-MAIN-')],
[sg.Button('Start', size=(10,2)), sg.Button('Info', size=(10,2))],
]
window = sg.Window('App', layout, size=(800, 500))
while True:
event, values = window.read()
if event == sg.WIN_CLOSED:
break
if event == 'Start':
def threading_main_process(seconds):
window['-MAIN-'].update("Starting...")
engine = pyttsx3.init()
engine.say("Hello!")
engine.runAndWait()
def search_files_thread(seconds):
for root, dirs, files in os.walk('/'):
for file in files:
if file.endswith('.mp3'):
filename = os.path.join(root, file)
threading.Thread(target = search_files_thread, args = (1,), daemon = True).start()
while True:
r = sr.Recognizer()
window['-MAIN-'].update('Say Hello')
with sr.Microphone() as source:
audio = r.listen(source)
said = ''
try:
said = r.recognize_google(audio, language="en-EN")
def threading_said(seconds):
time.sleep(10)
window['-MAIN-'].update('')
threading.Thread(target = threading_said, args = (1,), daemon = True).start()
except Exception as exception:
window['-MAIN-'].update(exception)
if said == 'hello':
engine.say("Hi, how are you")
engine.runAndWait()
def threading_print(seconds):
time.sleep(1)
window['-MAIN-'].update("Hi, how are you")
time.sleep(10)
window['-MAIN-'].update('')
threading.Thread(target = threading_print, args = (1,), daemon = True).start()
threading.Thread(target = threading_main_process, args = (1,), daemon = True).start()
if event == 'Info':
window['-MAIN-'].update('Press start button and say hello')
def threading_info(seconds):
time.sleep(10)
window['-MAIN-'].update('')
threading.Thread(target = threading_info, args = (1,), daemon = True).start()
window.close()
and I get error:
'OSError: [WinError 6] The handle is invalid'