Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Tk_sizable_screengrab.py
- import os, datetime
- def take_screenshot(x=0, y=0, width=None, height=None):
- try:
- import wx
- except ImportError as e:
- return 'Screenshot could not be taken - wx could not be imported: %s' %(e)
- folder_name = datetime.date.today().strftime('%Y-%m-%d')
- file_name = datetime.datetime.now().strftime('%H-%M-%S') + '.jpg'
- directory = 'C:\\Users\\test\\' + folder_name
- try:
- os.mkdir(directory)
- except: pass
- filename = os.path.join(directory, file_name)
- global filename
- app = wx.App()
- screen = wx.ScreenDC()
- size = screen.GetSize()
- if width == None:
- width = size[0]
- if height == None:
- height = size[1]
- bmp = wx.EmptyBitmap(width, height)
- mem = wx.MemoryDC(bmp)
- mem.Blit(0, 0, width, height, screen, x, y)
- del mem
- bmp.SaveFile(filename, wx.BITMAP_TYPE_PNG)
- take_screenshot(0,0,800,600)
- print 'Screenshot saved to file: %s' %(filename)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement