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')