I have a GUI application where the console is hidden (using the pyw
extension does not seem to allow the console to reappear) but now I need to make it reappear to allow user input. Here is my code currently:
import ctypes
kernel32 = ctypes.WinDLL('kernel32')
user32 = ctypes.WinDLL('user32')
SW_HIDE = 0
hWnd = kernel32.GetConsoleWindow()
user32.ShowWindow(hWnd, SW_HIDE)
import tkinter as tk
def show_console():
kernel32 = ctypes.WinDLL('kernel32')
user32 = ctypes.WinDLL('user32')
SW_SHOW = 5
hWnd = kernel32.GetConsoleWindow()
user32.ShowWindow(hWnd, SW_SHOW)
tk.Frame()
a = tk.Button(text = 'Make Console Appear', command=show_console)
a.pack()
tk.mainloop()
This hides and shows the console as desired however when it is first launched the windows shows briefly, then disappears. How can I prevent this?