python中实时查看鼠标所指的像素点的RBG数值

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
import time
import pyautogui
 
 
def rgb2hex(r, g, b):
    return '#{:02x}{:02x}{:02x}'.format(r, g, b)
 
 
try:
    width, height = pyautogui.size()
    while True:
        time.sleep(1)
        x, y = pyautogui.position()
        rgb = pyautogui.screenshot().getpixel((x, y))
        r = str(rgb[0]).rjust(3)
        g = str(rgb[1]).rjust(3)
        b = str(rgb[2]).rjust(3)
        hex_c = rgb2hex(int(r), int(g), int(b))
        color_str = f'选中颜色   RGB:({r},{g},{b}),  16进制:{hex_c}'
        print(color_str)
except KeyboardInterrupt:
    exit('\n\n---- Bye.\n')

  

posted @   小二君i  阅读(127)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· 阿里巴巴 QwQ-32B真的超越了 DeepSeek R-1吗?
· 【译】Visual Studio 中新的强大生产力特性
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
· 【设计模式】告别冗长if-else语句:使用策略模式优化代码结构
点击右上角即可分享
微信分享提示