python實現色彩空間轉換程式(Tkinter)

來源:互聯網
上載者:User
本文主要基於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程式設計有所協助。

  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    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.