asweigart / pyautogui

A cross-platform GUI automation Python module for human beings. Used to programmatically control the mouse & keyboard.
BSD 3-Clause "New" or "Revised" License
10.45k stars 1.26k forks source link

Pyautogui.screenshot(region=) does not accept a variable from another file #837

Closed Sqidy-P closed 9 months ago

Sqidy-P commented 9 months ago

Here is the code:

import main
import pyautogui

# main() contains game_cords = GetWindowRect(FindWindow(None, "..."))
cords = main.game_cords

def get_cards():

    # Debug
    print(main.game_cords)

    game = pyautogui.screenshot(region=cords)
    game.save(r"C:\\Users\\Sqidy\\PycharmProjects\\Solitare\\UI\\Game\\screenshot.png")

    pass

Once ran, this is the error:

...\venv\lib\site-packages\pyscreeze\__init__.py", line 540, in _screenshot_win32
    assert len(region) == 4, 'region argument must be a tuple of four ints'
AssertionError: region argument must be a tuple of four ints

I am on a windows system, latest version of python, using Pycharm. It will take a variable, but when I try to take it from another file, in this case being my main.py, it will not accept it as it's tuple.

Sqidy-P commented 9 months ago

While I do think this should be fixed, it has nothing to do with pyautogui, it's just how python is coded for some reason.

encleadus commented 9 months ago

I am receiving the same error, is there any solution on this?