0

I've written some code that automatically plays a minigame for me. But to do so I hard coded values. When trying to generalize the positions with the following code, it doesn't work.

import pyautogui as py

#cards = [(837, 928), (939, 928), (1040, 928), (1142, 928), (1244, 928)]
#coins = ((698, 492), (740, 492), (782, 492))

colors = (186, 251, 8, 243, 0, 178)

# My screen size is 1920 * 1080

hcard = (116/135) * py.size[1]
card1 = ((279/640) * py.size[0], hcard)
card2 = ((313/640) * py.size[0], hcard)
card3 = ((13/24) * py.size[0], hcard)
card4 = ((571/960) * py.size[0], hcard)
card5 = ((311/480) * py.size[0], hcard)
cards = (card1, card2, card3, card4, card5)

hcoin = (41/90) * py.size[1]
coin1 = ((231/640) * py.size[0], hcoin)
coin2 = ((37/96) * py.size[0], hcoin)
coin3 = ((49/120) * py.size[0], hcoin)
coins = (coin1, coin2, coin3)

I've tried rearranging the calculation and renaming the variable.

  • `pyautogui.size` is a function. You need to call it before you can use it, try `py.size()[1]` instead. You might also want to follow the [example usage](https://github.com/asweigart/pyautogui#keyboard-and-mouse-control) and assign `screenWidth, screenHeight = pyautogui.size()` and then use `screenWidth` or `screenHeight` directly instead. – metatoaster Nov 04 '22 at 02:52

0 Answers0