Advertisement
here2share

# Tk_uniquify_rgb_data_sort.py

Aug 21st, 2020
1,930
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.80 KB | None | 0 0
  1. # Tk_uniquify_rgb_data_sort.py
  2.  
  3. import Tkinter as tk
  4. from tkFileDialog import askopenfilename
  5. from PIL import Image, ImageTk
  6.  
  7. def openfile():
  8.     img_data = askopenfilename(filetypes=[('png files', '.png'), ('jpg files', '.jpg')])
  9.     image = Image.open(img_data)
  10.     rgb = image.convert("RGB")
  11.     sss = list(rgb.getdata())
  12.     ccc = set(sss)
  13.     d = {}
  14.     for i in ccc:
  15.         d[i] = sss.count(i)
  16.     ttt = sorted(d.items(), key=lambda value: value[1], reverse=True)
  17.     ttt = [z for z,x in ttt]
  18.    
  19.     t = 0
  20.     for c in ttt:
  21.         x = t%15*90
  22.         y = t/15*18
  23.         canvas.create_rectangle(x, y, x+90, y+18, fill="#%02x%02x%02x" % (c))
  24.         canvas.create_text(x+45, y+9, text=c, fill="white", font='Ariel 9')
  25.         canvas.update()
  26.         t += 1
  27. 0
  28.  
  29. ww=1400
  30. hh=720
  31. root = tk.Tk()
  32. canvas = tk.Canvas(root, width=ww, height=hh)
  33. canvas.pack()
  34. openfile()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement