Take a screenshot via a Python script on Linux

后端 未结 15 1247
暖寄归人
暖寄归人 2020-11-22 11:50

I want to take a screenshot via a python script and unobtrusively save it.

I\'m only interested in the Linux solution, and should support any X based environment.

15条回答
  •  甜味超标
    2020-11-22 12:20

    I couldn't take screenshot in Linux with pyscreenshot or scrot because output of pyscreenshot was just a black screen png image file.

    but thank god there was another very easy way for taking screenshot in Linux without installing anything. just put below code in your directory and run with python demo.py

    import os
    os.system("gnome-screenshot --file=this_directory.png")
    

    also there is many available options for gnome-screenshot --help

    Application Options:
      -c, --clipboard                Send the grab directly to the clipboard
      -w, --window                   Grab a window instead of the entire screen
      -a, --area                     Grab an area of the screen instead of the entire screen
      -b, --include-border           Include the window border with the screenshot
      -B, --remove-border            Remove the window border from the screenshot
      -p, --include-pointer          Include the pointer with the screenshot
      -d, --delay=seconds            Take screenshot after specified delay [in seconds]
      -e, --border-effect=effect     Effect to add to the border (shadow, border, vintage or none)
      -i, --interactive              Interactively set options
      -f, --file=filename            Save screenshot directly to this file
      --version                      Print version information and exit
      --display=DISPLAY              X display to use
    

提交回复
热议问题