Reputation: 166
I've created a little Python app, and I want it to hide the console window in the middle of the process, so renaming it as .pyw won't solve the problem.
It would be best to have some kind of function to minimize the window, any thoughts?
Upvotes: 2
Views: 5751
Reputation: 119
Much simpler method is to rename the main python source file's extension from py to pyw. This signals python that no console is required and it is a window'ed script.
E.g. rename PythonApp.py to PythonApp.pyw
Haven't tested but should work on all platforms.
Upvotes: 0
Reputation: 1
there is a good way to do it with cmd. open command prompt:
start /min py -x path\test.py
replace your version of python by 'x' and replace 'path' by the real path of your python project. this may help you to never see the console. you can start your program again in python like this:
import os
os.sysyem('start /min %~dp0test.py)
but I don't know the way to minimize the console in the middle of program.
Upvotes: 0
Reputation: 150
On windows you may use win32api:
from win32 import win32api
from win32 import win32process
from win32 import win32gui
def callback(hwnd, pid):
if win32process.GetWindowThreadProcessId(hwnd)[1] == pid:
# hide window
win32gui.ShowWindow(hwnd, 0)
# find hwnd of parent process, which is the cmd.exe window
win32gui.EnumWindows(callback, os.getppid())
Upvotes: 2