Mainly based on the Colorsys implementation, the example is from HLS to RGB, if you want to change the color space very easy only need to change a function
Scale and canvas components are used
The code is as follows:
from Tkinter import *import colorsys# operation response Function def update (* args): ' color ' r,g,b = col Orsys.hls_to_rgb (H.get ()/255.0, L.get ()/255.0, S.get ()/255.0) R,g,b = R * 255, G * 255, B * 255 rgb.configure ( Text = ' RGB: (%d,%d,%d) '% (R, G, b)) c.configure (bg = ' #%02x%02x%02x '% (R, G, b)) root = Tk () hue = Label (root, Text = ' Hue ') hue.grid (row = 0, column = 0) light = label (root, Text = ' lightness ') light.grid (row = 0, column = 1) Sat = label (Root, Text = ' saturation ') sat.grid (row = 0, column = 2) #初始化颜色为rgb的000, that is, pure black RGB = Label (root, Text = ' RGB (0, 0, 0) ') Rgb.grid (RO w = 0, column = 3) H = scale (root, from_ = 255, to = 0, command = update) H.grid (row = 1, column = 0) L = scale (root, From_ = 255, to = 0, command = update) L.grid (row = 1, column = 1) s = scale (root, from_ = 255, to = 0, command = update) S.grid (row = 1, column = 2) c = Canvas (root, Width = +, height = +, bg = ' Black ') c.grid (row = 1, column = 3) root.mainloop ()
Perform effects such as:
Using Python to implement color space conversion program based on Tkinter