Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Tk_uniquify_rgb_data_sort.py
- import Tkinter as tk
- from tkFileDialog import askopenfilename
- from PIL import Image, ImageTk
- def openfile():
- img_data = askopenfilename(filetypes=[('png files', '.png'), ('jpg files', '.jpg')])
- image = Image.open(img_data)
- rgb = image.convert("RGB")
- sss = list(rgb.getdata())
- ccc = set(sss)
- d = {}
- for i in ccc:
- d[i] = sss.count(i)
- ttt = sorted(d.items(), key=lambda value: value[1], reverse=True)
- ttt = [z for z,x in ttt]
- t = 0
- for c in ttt:
- x = t%15*90
- y = t/15*18
- canvas.create_rectangle(x, y, x+90, y+18, fill="#%02x%02x%02x" % (c))
- canvas.create_text(x+45, y+9, text=c, fill="white", font='Ariel 9')
- canvas.update()
- t += 1
- 0
- ww=1400
- hh=720
- root = tk.Tk()
- canvas = tk.Canvas(root, width=ww, height=hh)
- canvas.pack()
- openfile()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement