Screenshots
Thorsten Kohnhorst
monsterkodi at gmx.net
Thu Jun 5 05:18:48 EDT 2003
Hello Sam,
> I am looking for a way to take screenshots of the desktop. The files
> don't need to be opened or viewed, just saved with a filename the user
> gives. I'm developing this in a Windows environment. If you could give
> me any links or hints about this I would be most appreciative.
There are many ways to do this and they depend mostly on the frameworks
you are using.
Here is a short example how to write a screenshot to a bitmap using
wxPython:
from wxPython.wx import *
def screenshot(filename='screenshot.bmp'):
"""writes a screenshot to a bitmap (.bmp)"""
screenDC, memDC = wxScreenDC(), wxMemoryDC() # device contexts
width, height = screenDC.GetSizeTuple() # screen size
bitmap = wxEmptyBitmap(width, height) # create bitmap
memDC.SelectObject(bitmap) # select bitmap
memDC.Blit(0, 0, width, height, screenDC, 0, 0) # copy screen
bitmap.SaveFile(filename, wxBITMAP_TYPE_BMP) # save bitmap
Hope that helps,
yours kodi
More information about the Python-list
mailing list