码迷,mamicode.com
首页 > 编程语言 > 详细

基于Tkinter利用python实现颜色空间转换程序

时间:2016-06-30 14:07:35      阅读:463      评论:0      收藏:0      [点我收藏+]

标签:

主要基于colorsys实现,例子是从hls转换到rgb,假设要换颜色空间非常easy仅仅须要改动一个函数

用到了Scale和Canvas组件

代码例如以下:

from Tkinter import *
import colorsys
#操作后的响应函数
def update(* args):
    ‘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)
#初始化颜色为rgb的000,也就是纯黑色
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()


执行效果例如以下图:

技术分享技术分享

基于Tkinter利用python实现颜色空间转换程序

标签:

原文地址:http://www.cnblogs.com/tkinter/p/5629601.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!