Take a screenshot via a python script. [Linux]

2018-12-31 16:44发布

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条回答
呛了眼睛熬了心
2楼-- · 2018-12-31 16:57

bit late but nevermind easy one is

import autopy
import time
time.sleep(2)
b = autopy.bitmap.capture_screen()
b.save("C:/Users/mak/Desktop/m.png")
查看更多
牵手、夕阳
3楼-- · 2018-12-31 16:59

You can use this

import os
os.system("import -window root screen_shot.png")
查看更多
流年柔荑漫光年
4楼-- · 2018-12-31 17:01
import ImageGrab
img = ImageGrab.grab()
img.save('test.jpg','JPEG')

this requires Python Imaging Library

查看更多
弹指情弦暗扣
5楼-- · 2018-12-31 17:02

From this thread:

 import os
 os.system("import -window root temp.png")
查看更多
长期被迫恋爱
6楼-- · 2018-12-31 17:03

Cross platform solution using wxPython:

import wx
wx.App()  # Need to create an App instance before doing anything
screen = wx.ScreenDC()
size = screen.GetSize()
bmp = wx.EmptyBitmap(size[0], size[1])
mem = wx.MemoryDC(bmp)
mem.Blit(0, 0, size[0], size[1], screen, 0, 0)
del mem  # Release bitmap
bmp.SaveFile('screenshot.png', wx.BITMAP_TYPE_PNG)
查看更多
余欢
7楼-- · 2018-12-31 17:04

There is a python package for this Autopy

The bitmap module can to screen grabbing (bitmap.capture_screen) It is multiplateform (Windows, Linux, Osx).

查看更多
登录 后发表回答