with mss.mss() as sct: box ={"top":50,"left":50,"width":200,"height":200} im = sct.grab(box) mss.tools.to_png(im.rgb,im.size,output="1.png")

获取一个或多个像素点

#encoding=utf-8
import mss
from PIL import Image
with mss.mss() as sct:
    box ={"top":0,"left":0,"width":200,"height":200}   
    sct_img = sct.grab(box)
    #pixel = sct_img.pixel(0, 0)
    #print(pixel)
    img = Image.new("RGB", sct_img.size)
    pixels = zip(sct_img.raw[2::4], sct_img.raw[1::4], sct_img.raw[::4])
    a = list(pixels)
    #print(a)
    img.putdata(a)   
    #img.show()     

 监控某区域出现像素点

#encoding=utf-8
import mss,time
from PIL import Image
with mss.mss() as sct:
    box ={"top":70,"left":220,"width":9,"height":12}
    while True:
        time.sleep(0.2)#不希望太快了
        sct_img = sct.grab(box)
        img = Image.new("RGB", sct_img.size)
        pixels = zip(sct_img.raw[2::4], sct_img.raw[1::4], sct_img.raw[::4])
        a = list(pixels)
        if (192,0,192) in a:
            print("出现")
        else:
            print("消失")