Last active
February 21, 2023 17:59
-
-
Save Dadangdut33/58d06ed42f55063353eca1fbacb91e70 to your computer and use it in GitHub Desktop.
Toggling hide console/terminal including windows terminal in python
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import ctypes | |
import win32.lib.win32con as win32con | |
import win32gui # pip install pywin32 | |
from time import sleep | |
kernel32 = ctypes.WinDLL('kernel32') | |
user32 = ctypes.WinDLL('user32') | |
a = input('Input value here:') | |
# get the console window | |
hWnd = kernel32.GetConsoleWindow() | |
# set it as foreground | |
win32gui.SetForegroundWindow(hWnd) | |
# get the foreground window | |
hWnd = win32gui.GetForegroundWindow() | |
# hide it | |
win32gui.ShowWindow(hWnd, win32con.SW_HIDE) | |
print("I'm hidden!") | |
sleep(2) | |
# show again | |
win32gui.ShowWindow(hWnd, win32con.SW_SHOW) | |
print("I'm not hidden anymore!") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment