'python ctypes does not show console

I want to hide the console and show. But after I hid it does not show

ctypes.windll.user32.ShowWindow(ctypes.windll.user32.FindWindowW(None, "L"), 1 if click_thread.hide_status else 0 )


Solution 1:[1]

Make sure to fully define the .argtypes and .restype of each function you use. ctypes defaults aren't always best. Below works:

import ctypes as ct
from ctypes import wintypes as w

SW_HIDE = 0
SW_SHOW = 5

dll = ct.WinDLL('user32')
# BOOL ShowWindow(HWND hWnd, int nCmdShow);
dll.ShowWindow.argtypes = w.HWND, ct.c_int
dll.ShowWindow.restype = w.BOOL
# HWND FindWindowW(LPCWSTR lpClassName, LPCWSTR lpWindowName);
dll.FindWindowW.argtypes = w.LPCWSTR, w.LPCWSTR
dll.FindWindowW.restype = w.HWND

h = dll.FindWindowW(None, 'Console')
dll.ShowWindow(h, SW_HIDE)
input(': ')
dll.ShowWindow(h, SW_SHOW)

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Mark Tolonen