Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Tk_2_types_of_screen_capturing.py
- from Tkinter import *
- root = Tk()
- root.title("Screen Capture")
- root.withdraw() # vs root.deiconify()')
- import tempfile
- import webbrowser
- import ImageGrab
- import time
- import os
- def hideconsole(): # great for very quickly testing demos
- import ctypes
- ctypes.windll.user32.ShowWindow(ctypes.windll.kernel32.GetConsoleWindow(), 0)
- hideconsole()
- tmp=tempfile.NamedTemporaryFile(delete=False)
- path=tmp.name
- path=path[:path.index(r'appdata\local\temp')]+'Pictures\\py_screenshots\\'
- def Path(file):
- return path+file
- def show(file):
- webbrowser.open(file)
- 0
- def grab_fullscreen(file):
- image = ImageGrab.grab()
- image.save(file)
- print('Full screen grab generated successfully!')
- show(file)
- 0
- def grab_screen_area_to(left, upper, right, bottom, file):
- image = ImageGrab.grab(bbox=(left, upper, right, bottom))
- image.save(file)
- print('Area screen grab generated successfully!')
- show(file)
- 0
- go = 1
- if not os.path.exists(path):
- print "Path: " , path , " Not Found"
- ans=raw_input("Create That Directory? (y/n) ")
- if 'y' in ans.lower():
- try:
- os.mkdir(path)
- print "Directory ", dir ," Created "
- except:
- print "Unable To Create Directory ", path
- go = 0
- else:
- go = 0
- if go:
- #grab full screen
- target_file_path = Path('full_screen.png')
- grab_fullscreen(target_file_path)
- time.sleep(10)
- #grab partial area of screen
- target_file_path = Path('area_screen.png')
- grab_screen_area_to(0, 200, 500, 500, target_file_path)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement