Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import pygetwindow as gw
- import pyautogui
- def take_window_region_screenshot(window_title, region):
- # Get the specified window by title
- window = gw.getWindowsWithTitle(window_title)[0]
- # Calculate the absolute coordinates of the specified region inside the window
- absolute_region = (
- window.left + region[0],
- window.top + region[1],
- window.left + region[2],
- window.top + region[3]
- )
- # Capture the screenshot based on the absolute coordinates
- screenshot = pyautogui.screenshot(region=(absolute_region[0], absolute_region[1], absolute_region[2]-absolute_region[0], absolute_region[3]-absolute_region[1]))
- # Save the screenshot to a file (adjust the filename as needed)
- screenshot.save("window_region_screenshot.png")
- print("Screenshot saved to 'window_region_screenshot.png'")
- if __name__ == "__main__":
- # Specify the title of the window you want to capture
- target_window_title = "StateOfDecay2"
- modifier = 590
- # Specify the coordinates of the region inside the window
- target_region = (290+modifier, 695, 400+modifier, 715)
- # Take a screenshot of the specified window region
- take_window_region_screenshot(target_window_title, target_region)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement