简体   繁体   English

如何在python中获取屏幕上的像素颜色

[英]how to get pixel color on screen in python

I'm really really beginning/nooby in this and i'm trying to detect the color green on my screen and when it shows up click the mouse button. 我真的真的开始/ nooby在这里,我试图检测我的屏幕上的绿色,当它出现时单击鼠标按钮。 im also using sublime text 2 but I also have idle. 我也使用崇高的文字2,但我也有空闲。

    import ImageGrab
    import time
    time.clock()
    image = ImageGrab.grab()
    for y in range(0, 100, 10):
        for x in range(0, 100, 10):
            color = image.getpixel((x, y))
    print(time.clock())

i tried this but it just gives me this "ModuleNotFoundError: No module named 'ImageGrab'" I have been scouring the internet for littarl hours and i just cant find any tutorials that help with installing pillow. 我试过这个,但它只是给了我“ModuleNotFoundError:没有名为'ImageGrab'的模块”我一直在互联网上搜索littarl小时,我只是找不到任何有助于安装枕头的教程。 this is ridiculously complicated and im about to give up 这是非常复杂的,我即将放弃

Instead of 代替

import ImageGrab

use 采用

from PIL import ImageGrab

You should have PIL already installed. 您应该已经安装了PIL。 PIL is the "Python Image Library" and can be downloaded from https://www.pythonware.com/products/pil/ PIL是“Python图像库”,可以从https://www.pythonware.com/products/pil/下载

Note that PIL is quite old and seems to be only available for Python 2.x (and even older). 请注意,PIL很老,似乎只适用于Python 2.x(甚至更旧)。 You could also use the Python package Pillow instead, which is a fork of PIL. 您也可以使用Python包Pillow,它是PIL的一个分支。 This can be installed using pip install Pillow in (recent versions of) Python 2 as well as 3. 这可以使用pip install Pillow (最近版本的)Python 2以及3来安装。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM