Advertisement
bolodev

Untitled

Nov 26th, 2023
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.25 KB | None | 0 0
  1. import pygetwindow as gw
  2. import pyautogui
  3.  
  4. def take_window_region_screenshot(window_title, region):
  5. # Get the specified window by title
  6. window = gw.getWindowsWithTitle(window_title)[0]
  7.  
  8. # Calculate the absolute coordinates of the specified region inside the window
  9. absolute_region = (
  10. window.left + region[0],
  11. window.top + region[1],
  12. window.left + region[2],
  13. window.top + region[3]
  14. )
  15.  
  16. # Capture the screenshot based on the absolute coordinates
  17. screenshot = pyautogui.screenshot(region=(absolute_region[0], absolute_region[1], absolute_region[2]-absolute_region[0], absolute_region[3]-absolute_region[1]))
  18.  
  19. # Save the screenshot to a file (adjust the filename as needed)
  20. screenshot.save("window_region_screenshot.png")
  21. print("Screenshot saved to 'window_region_screenshot.png'")
  22.  
  23. if __name__ == "__main__":
  24. # Specify the title of the window you want to capture
  25. target_window_title = "StateOfDecay2"
  26.  
  27. modifier = 590
  28. # Specify the coordinates of the region inside the window
  29. target_region = (290+modifier, 695, 400+modifier, 715)
  30.  
  31. # Take a screenshot of the specified window region
  32. take_window_region_screenshot(target_window_title, target_region)
  33.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement