能够实时显示鼠标所在位置的RBG(带弹窗),便于实时取色,创作不易,喜欢的话麻烦点赞收藏哟~
# -*- coding: utf-8 -*-
import pyautogui, sys
from ctypes import * # 获取屏幕上某个坐标的颜色
def GetColor():
r = 0
g = 0
b = 0
try:
x, y = pyautogui.position()
gdi32 = windll.gdi32
user32 = windll.user32
hdc = user32.GetDC(None) # 获取颜色值
pixel = gdi32.GetPixel(hdc, x, y) # 提取RGB值
r = pixel & 0x0000ff
g = (pixel & 0x00ff00) >> 8
b = pixel >> 16
except KeyboardInterrupt:
print('\n')
return r,g,b
import tkinter as tk
window = tk.Tk()
window.wm_attributes('-topmost', 1)
window.title('小白取色器')
window.geometry('200x100')
a = tk.StringVar()
l = tk.Label(window, textvariable=a, # 标签的文字
bg='green', # 标签背景颜色
font=('Arial', 12), # 字体和字体大小
width=15, height=2 # 标签长宽(以字符长度计算)
)
l.pack() # 固定窗口位置
while 1:
r,g,b = GetColor()
print(str(r) + ',' + str(g) + ',' + str(b))
a.set(str(r)+','+str(g)+','+str(b))
l.update()
window.mainloop()
另外我写了一篇能够获取鼠标实时位置(带弹窗)的博客:(48条消息) 实时获取鼠标位置_晋升阁的博客-CSDN博客
欢迎来踩!!!