Advertisement
here2share

# Tk_askopenfilename_ImageTk.py

Aug 31st, 2020
1,642
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.91 KB | None | 0 0
  1. # Tk_askopenfilename_ImageTk.py # if... image "pyimage1" doesn't exist ???
  2.  
  3. from Tkinter import *
  4. from PIL import Image, ImageTk
  5. import random
  6.  
  7. root = Tk()
  8. root.title("Tk_askopenfilename_ImageTk")
  9. ww = 1400
  10. hh = 720
  11. root.geometry("%dx%d+-10+0"%(ww,hh))
  12. canvas = Canvas(root, width=ww, height=hh)
  13. canvas.pack()
  14.  
  15. ppp = '0 64 128 192 255'.split()
  16. from tkFileDialog import askopenfilename
  17. img_data = askopenfilename(filetypes=[('png files', '.png')]) # needs to be placed after pack()
  18.  
  19. image = Image.open(img_data)
  20. imw,imh = image.size
  21. img = Image.new('RGB', (imw,imh))
  22. rgb = image.convert("RGB")
  23. sss = list(rgb.getdata())
  24. ttt = set(sss)
  25. sss = str(sss)
  26. '''
  27. for t in ttt:
  28.     rgb = '(%s, %s, %s)'%tuple([ppp[z/52] for z in t])
  29.     sss = sss.replace(str(t),str(rgb))
  30. '''
  31. sss = eval(sss)
  32.  
  33. img.putdata(sss)
  34. imgTk = ImageTk.PhotoImage(img)
  35. canvas.create_image(10, 10, anchor=NW, image=imgTk)
  36. root.update()
  37.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement