#πŸ”’ Cannot check pixel on screen with pyautogui.

30 messages Β· Page 1 of 1 (latest)

spark pine
#

The code works on my computer, though not my laptop. Gives me this error:
elif runloop != 1 and pyautogui.pixel(946, 1100) != (0, 0, 0):
~~~~~~~~~~~~~~~^^^^^^^^^^^
File "C:\Users\unkl0kk\AppData\Local\Programs\Python\Python313\Lib\site-packages\pyscreeze_init_.py", line 759, in pixel
raise WindowsError("windll.gdi32.GetPixel failed : return {}".format(color))
OSError: windll.gdi32.GetPixel failed : return -1

Please help! Running on windows 10, python version 3.13.7.

glacial schoonerBOT
#

@spark pine

Python help channel opened

Remember to:

  • Ask your Python question, not if you can ask or if there's an expert who can help.
  • Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
  • Explain what you expect to happen and what actually happens.

:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.

spark pine
#
import os
import keyboard
import time
import random
import string
import pyautogui  # type: ignore
import schedule # type: ignore
import time
#Point(x=946, y=1060)
#Point(x=857, y=482)
import random
open("seedlist.txt", "a").write("\n")
runloop = 1
run = 1
md = 0
pd = 0
def restart():
    keyboard.press_and_release("alt + f4")
#    print("reset moment")
    global runloop
    runloop = 1
schedule.every(30).minutes.do(restart)
while run == 1:
    #t = Timer(30 * 60, restart)
    #t.start()
    #t.join()
    schedule.run_pending()
    if runloop == 1:
        seed = ''.join(random.choices(string.digits + string.ascii_letters + string.punctuation, k=random.randint(1, 10)))
        #seed = "insertseed"
        print(f"Using seed {seed}...")
        open("seedlist.txt", "a").write(f"{seed}\n")
        os.popen(r'"c:/Users/unkl0kk/Desktop/SourceVoid Online/SourcevoidOnline.exe"')
        time.sleep(5)
        pyautogui.click(857, 482)
        #Point(x=1112, y=698)
        keyboard.write(f"{seed}")
        pyautogui.click(1112, 698)
        runloop = 0
    elif runloop != 1 and pyautogui.pixel(946, 1100) != (0, 0, 0):
        restart()
while md == 1:
    print(pyautogui.position())
while pd == 1:
    #print(pyautogui.pixel(1179, 1388))
    if pyautogui.pixel(1029, 1388) != (0, 0, 0):
        print(pyautogui.pixel(1179, 1388))```
#

(yes, i changed the positions of pixels to match the laptop's screen resolution.)

golden bridge
#

Can you reduce the problem to a tiny script? i.e. make a separate script for this.
Typical answers on the web suggest the pixel coordinate isn't valid (eg off screen or something).
So maybe make a tiny loop to get pixel values until it fails; the point where it fails might tell you something.

#

(I'm not on windows and have never used pyautogui, this is just generic debugging suggestions.)

spark pine
#

i don't think that would be the case, as i used mouse coords to reset these to valid values when changing from the computer to the laptop. will check anyway, though

#

the specific line of code that's not working is this, throwing an error about "windll.gdi32.GetPixel" failing

#

(this is "restart()")

golden bridge
#

Well it's pretty clearly failing in .pixel(), hence the suggestion to write a loop to just try that with many coords until it fails. Print each coord before the .pixel() call so you know what you were up to.

#

What's the screen res?

spark pine
#

1920x1080

#

on the pc i used to run this on it was 2560x1440

#

i changed the coords of the pixel to be in range of the resolution tho

golden bridge
#

Your y value is 1100 - that's more than 1080

spark pine
#

oh

#

i'm

#

extremely dumb lmao

#

soz

golden bridge
#

You can look up the current screen res I believe. You could do some sanity checks up front, or compute the expected position of the pixel you're after perhaps.

#

Sometimes the obvious things are invisible to us; another pair of eyes is needed to see them. We see what we though was correct.

spark pine
#

iirc it was at 1060 before, then i realized "hey using chat to make it think i landed and making it reset isn't working anymore" and set it to 1100 (forgetting that reso was lower), then when stuff started breaking i somehow forgot that i made this change entirely ._.

golden bridge
#

You've got a lot of hardwired numbers in that script. I'd define those up the top in variables. That way you can see then in one place, maybe autocheck them before the code gets going, etc etc.

spark pine
#

i have plans to make a way to configure it using another script later so i don't have to tell ppl to change multiple lines of code just to automatically check seeds (that script would work with json or some other way of storing settings easily) but anyways ty for telling me this!

golden bridge
#

Have fun.

spark pine
#

seems to be working now!

#

(i mean, exept using chat to reset but that was accidental anyways (i will prolly make a keybind to quit while not focused on python))

glacial schoonerBOT
#
Python help channel closed for inactivity

This help channel has been closed. Feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.