This simple Python code uses the Tkinter GUI toolkit and the Python Image Library (PIL) to create a program that allows you to grab an image of the display screen (or portion of it) and save it to an image file. Unfortunately, the ImageGrab.grab() method only works on a Windows computer. Sorry about that to all you good folks using PC Linux or Apple Unix. I guess we have to ask the PIL folks to get on the ball!
# use a modified Tkinter keylogger and PIL ImageGrab to # grab the screen image and save to an image file # the ImageGrab.grab() function works with Windows only! # download Python Image Library (PIL) free from: # http://www.pythonware.com/products/pil/index.htm # tested with Python25 on Vista EU 05/15/2007 import Tkinter as tk import ImageGrab # PIL def key(event): """modified Tkinter keylogger""" if event.keysym == 'F7': root.bell() # don't show window, move to taskbar as icon root.iconify() # small delay to allow tk window to fade on LCDs for x in range(1000000): x = x + 77 # this will grab the whole screen display and save it to a file img = ImageGrab.grab() img.save("screenImage1.jpg") # this will grab a 400 pixel wide and 300 pixel heigh partion # upper left corner screen coordinates x=0, y=0 img = ImageGrab.grab((0, 0, 400, 300)) img.save("screenImage2.jpg") root = tk.Tk() root.title('Screen Image Grabber') str1 = """\ Key F7 will make this program move to the taskbar as an icon and then take a image grab of the screen and save to a file """ tk.Label(root, text=str1, bg='yellow').pack() root.bind_all('<Key>', key) root.mainloop()
Be a part of the DaniWeb community
We're a friendly, industry-focused community of 1.19 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.