Dan Jones
Dan Jones

Reputation: 47

win32gui.GetPixel() not working: pywintypes.error: (0, 'GetPixel', 'No error message is available')

In my own pysimplegui program, and others, every time I use GetPixel, I get the error: pywintypes.error: (0, 'GetPixel', 'No error message is available').

while True:                             # The Event Loop
event, values = window.read()
hwnd = win32gui.FindWindow(None, 'Window that stays open')
rgbint2rgbtuple(win32gui.GetPixel(hwnd, 100, 100))

print(event, values)
if event == sg.WIN_CLOSED or event == 'Exit':
    break

the only time it didn't crash was with google chrome, but it gave the wrong RGB values. Any ideas?

Upvotes: 1

Views: 1965

Answers (1)

Jason Yang
Jason Yang

Reputation: 13051

You may use following way the get value of pixel,

import win32ui

w = win32ui.FindWindow(None, 'Window that stays open')
dc = w.GetWindowDC()
color = dc.GetPixel(100, 100)

Should check the case if window 'Window that stays open' not found or with wrong title. confirm what title of your window by following code. Also confirm point(x, y) in your window.

import win32gui

def enumWindowFunc(hwnd, windowList):
    text = win32gui.GetWindowText(hwnd)
    className = win32gui.GetClassName(hwnd)
    if text and className != "IME":
        print(repr(text), repr(className))

win32gui.EnumWindows(enumWindowFunc, [])

Upvotes: 2

Related Questions