Python implements the color space Conversion Program (Tkinter), pythontkinter
This article is mainly implemented based on colorsys. The example is to convert from hls to rgb. If you want to change the color space, you only need to modify one function. The specific content is as follows:
UsedScale and Canvas Components.
Run:
The Code is as follows:
From Tkinter import * import colorsys # response function def update (* args) after the operation: 'color' r, g, B = colorsys. 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) # initialize the 000 color of rgb, that is, pure black rgb = Label (root, text = 'rgb (0, 0, 0 )') rgb. grid (row = 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 = 100, height = 100, bg = 'black') c. grid (row = 1, column = 3) root. mainloop ()
The above is all of the content in this article, hoping to help you learn Python programming.
Articles you may be interested in:
- Python3 uses tkinter to implement a simple ui instance
- How does python output color-coded text in linux?
- Python tkinter Layout-Simple Chat Window implementation
- Python Tkinter simple layout example tutorial
- Python Tkinter basic control usage
- Use the Tkinter module in Python to create GUI program instances
- Python implements color rgb and hex conversion functions