This is straight from Google AI, and seems to work well for me.
import ctypes
def focus_console():
kernel32 = ctypes.windll.kernel32
user32 = ctypes.windll.user32
SW_SHOW = 5
console_window = kernel32.GetConsoleWindow()
if console_window:
user32.ShowWindow(console_window, SW_SHOW)
user32.SetForegroundWindow(console_window)
# Example usage (assuming driver is already initialized and a browser window is open)
# ... your Selenium code to launch the browser ...
focus_console()
# ... continue with console-based operations ...