Search code examples
pythonscreenshotpyautogui

Take a screenshot without Python console window showing


This runs okay, but, when I run it, the screenshot includes also the python.exe window which pops up while running the code. I don't want the window to be in the screenshot. Any suggestions?

img = pyautogui.screenshot('Screenshot.png')

Solution

  • you change your filename extension to .Pyw

    screenshot.pyw for example

    What is a PYW file?

    The PYW file type is primarily associated with Python by Python Software Foundation. PYW files are used in Windows to indicate a script needs to be run using PYTHONW.EXE instead of PYTHON.EXE in order to prevent a DOS console from popping up to display the output. This patch makes it possible to import such scripts, in case they're also usable as modules.