国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > Python > 正文

python實現顏色空間轉換程序(Tkinter)

2019-11-25 16:59:57
字體:
來源:轉載
供稿:網友

本文主要基于colorsys實現,樣例是從hls轉換到rgb,如果要換顏色空間很容易只需要修改一個函數,具體內容如下

用到了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() 

以上就是本文的全部內容,希望對大家的學習Python程序設計有所幫助。

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 黔西县| 泽库县| 丰台区| 瓦房店市| 墨江| 监利县| 林西县| 霍邱县| 青铜峡市| 肥东县| 抚远县| 弥渡县| 巴塘县| 古丈县| 平阴县| 高密市| 西贡区| 临沧市| 兖州市| 临泉县| 房产| 涟源市| 东城区| 德化县| 汪清县| 中牟县| 崇信县| 海宁市| 江川县| 西乌| 高淳县| 宜黄县| 柳江县| 孟津县| 绩溪县| 天镇县| 琼结县| 泰和县| 神池县| 綦江县| 阿城市|