代码拉取完成,页面将自动刷新
#!/usr/bin/env python
# -*- coding: utf-8 -*-
'''采用PySimpleGUI的调色盘程序'''
import numpy as np
import cv2
import PySimpleGUI as sg
# 界面风格
sg.theme('GreenTan')
slider_r=[ sg.Text('红色分量', size=(10, 1)),
sg.Slider(range=(0,255),size=(40,15),resolution=1,change_submits=True,
orientation='horizontal',key='-SLIDER_R-')]
slider_g=[ sg.Text('绿色分量', size=(10, 1)),
sg.Slider(range=(0,255),size=(40,15),resolution=1,change_submits=True,
orientation='horizontal',key='-SLIDER_G-')]
slider_b=[ sg.Text('蓝色分量', size=(10, 1)),
sg.Slider(range=(0,255),size=(40,15),resolution=1,change_submits=True,
orientation='horizontal',key='-SLIDER_B-')]
image_palette=[sg.Image(key='-IMAGE_PALETTE-',size=(400,400))]
window = sg.Window('调色盘',
[slider_r,slider_g,slider_b,[sg.HorizontalSeparator()],image_palette],
font=("Helvetica", 15),element_justification="center" )
img = np.zeros((400,400,3), np.uint8)
#事件循环
while True:
# 读取界面操作
event, values = window.read()
# 检测是否需要退出
if event == sg.WIN_CLOSED:
break
r=np.uint8(values['-SLIDER_R-'])
g=np.uint8(values['-SLIDER_G-'])
b=np.uint8(values['-SLIDER_B-'])
img[:] = [b,g,r]
imgbytes = cv2.imencode(".png", img)[1].tobytes()
window["-IMAGE_PALETTE-"].update(data=imgbytes)
cv2.waitKey(0)
cv2.destroyAllWindows()
window.close()
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。