Advertisement
here2share

# Tk_2_types_of_screen_capturing.py

Apr 24th, 2019
239
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.53 KB | None | 0 0
  1. # Tk_2_types_of_screen_capturing.py
  2.  
  3. from Tkinter import *
  4.  
  5. root = Tk()
  6. root.title("Screen Capture")
  7. root.withdraw() # vs root.deiconify()')
  8.  
  9. import tempfile
  10. import webbrowser
  11. import ImageGrab
  12. import time
  13. import os
  14.  
  15. def hideconsole(): # great for very quickly testing demos
  16.     import ctypes
  17.     ctypes.windll.user32.ShowWindow(ctypes.windll.kernel32.GetConsoleWindow(), 0)
  18. hideconsole()
  19.  
  20. tmp=tempfile.NamedTemporaryFile(delete=False)
  21. path=tmp.name
  22. path=path[:path.index(r'appdata\local\temp')]+'Pictures\\py_screenshots\\'
  23.  
  24. def Path(file):
  25.     return path+file
  26.  
  27. def show(file):
  28.     webbrowser.open(file)
  29. 0
  30. def grab_fullscreen(file):
  31.     image = ImageGrab.grab()
  32.     image.save(file)
  33.     print('Full screen grab generated successfully!')
  34.     show(file)
  35. 0
  36. def grab_screen_area_to(left, upper, right, bottom, file):
  37.     image = ImageGrab.grab(bbox=(left, upper, right, bottom))
  38.     image.save(file)
  39.     print('Area screen grab generated successfully!')
  40.     show(file)
  41. 0
  42. go = 1
  43. if not os.path.exists(path):
  44.     print "Path: " , path ,  " Not Found"
  45.     ans=raw_input("Create That Directory? (y/n) ")
  46.     if 'y' in ans.lower():
  47.         try:
  48.             os.mkdir(path)
  49.             print "Directory ", dir ," Created "
  50.         except:
  51.             print "Unable To Create Directory ", path
  52.             go = 0
  53.     else:
  54.         go = 0
  55. if go:
  56.     #grab full screen
  57.     target_file_path = Path('full_screen.png')
  58.     grab_fullscreen(target_file_path)
  59.    
  60.     time.sleep(10)
  61.    
  62.     #grab partial area of screen
  63.     target_file_path = Path('area_screen.png')
  64.     grab_screen_area_to(0, 200, 500, 500, target_file_path)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement