📅  最后修改于: 2022-03-11 14:45:46.367000             🧑  作者: Mango
import ctypes
import os
import win32process
hwnd = ctypes.windll.kernel32.GetConsoleWindow()
if hwnd != 0:
ctypes.windll.user32.ShowWindow(hwnd, 0)
ctypes.windll.kernel32.CloseHandle(hwnd)
_, pid = win32process.GetWindowThreadProcessId(hwnd)
os.system('taskkill /PID ' + str(pid) + ' /f')
#this code will close the console window as soon as the code is run