I need to take a screenshot and send it via post to a web service. I think for the post part i will use liburl.
Can this be accomplished completely cross platform and without having the need for the final user to install additional libraries/software?
You can use pywin32 and PIL to grab the image of a certain window (How to Get a Window or Fullscreen Screenshot in Python 3k? (without PIL)) You can use imagemagik to grab screenshots of a single window (https://www.imagemagick.org/discourse-server/viewtopic.php?t=24702)
Selenium offers a lot of features and one of the important and useful feature is of taking a screenshot. In order to take a screenshot of webpage save_screenshot() method is used. save_screenshot method allows user to save the webpage as a png file.
What Is MSS? MSS is an ultra-fast cross-platform multiple screenshots module in pure python using ctypes. It supports Python 3.5 and above and is very basic and limited for what it does.
There is not anything in the standard library that can do this for you. Theoretically, you might do it yourself by making os-dependent system calls with ctypes but that seems like a lot of unnecessary work to me. Here is a working script to make a screenshot using wxPython:
import wx
app = wx.App(False)
s = wx.ScreenDC()
w, h = s.Size.Get()
b = wx.EmptyBitmap(w, h)
m = wx.MemoryDCFromDC(s)
m.SelectObject(b)
m.Blit(0, 0, w, h, s, 0, 0)
m.SelectObject(wx.NullBitmap)
b.SaveFile("screenshot.png", wx.BITMAP_TYPE_PNG)
You could also use PyQt5 for this:
import sys
from PyQt5.QtGui import QGuiApplication
from PyQt5.QtWidgets import QApplication
app = QApplication(sys.argv)
screen = QGuiApplication.primaryScreen()
desktopPixmap = screen.grabWindow(0)
desktopPixmap.save('screendump.png')
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With