Python implementation of color space conversion program (Tkinter)

Source: Internet
Author: User
This paper is mainly based on colorsys implementation, the sample is from HLS to RGB, if you want to change the color space is very easy to modify only a function, the specific content is as follows

Scale and canvas components are used.

Run:

The code is as follows:

from Tkinter import * Import Colorsys #操作后的响应函数 def update (* args): ' color ' r,g,b = Colorsys.hl S_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 = ' RG B: (%d,%d,%d) '% (R, G, b)) c.configure (bg = ' #%02x%02x%02x '% (R, G, b)) root = Tk () hue = Label (root, Text = ' hue ') h Ue.grid (row = 0, column = 0) light = label (root, Text = ' lightness ') light.grid (row = 0, column = 1) Sat = label (Root, T ext = ' saturation ') sat.grid (row = 0, column = 2) #初始化颜色为rgb的000, 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 = +, height = +, bg = ' Black ') c.grid (row = 1, column = 3) root . Mainloop () 

The above is the whole content of this article, I hope that everyone's learning Python programming help.

  • Related Article

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.