Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bring up python console window from running .pyw script

I have a script where normally I would not want the console window displayed like a .py file does and using the .pyw extension does that just as it's designed to do.

My question, is there a way to bring the running script's console window up from a .pyw file?

like image 857
tgikal Avatar asked Feb 18 '26 00:02

tgikal


1 Answers

Ended up going with the method of using a .py file and suppressing the console window.

Bound a simple toggle function to a button:

import ctypes

def raise_console(console_toggle):
    """Brings up the Console Window."""
    if console_toggle:
        # Show console
        ctypes.windll.user32.ShowWindow(ctypes.windll.kernel32.GetConsoleWindow(), 4)
    else:
        # Hide console
        ctypes.windll.user32.ShowWindow(ctypes.windll.kernel32.GetConsoleWindow(), 0)
    console_toggle = not console_toggle

console_toggle = False
like image 66
tgikal Avatar answered Feb 19 '26 12:02

tgikal



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!