Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Tk_askopenfilename_ImageTk.py # if... image "pyimage1" doesn't exist ???
- from Tkinter import *
- from PIL import Image, ImageTk
- import random
- root = Tk()
- root.title("Tk_askopenfilename_ImageTk")
- ww = 1400
- hh = 720
- root.geometry("%dx%d+-10+0"%(ww,hh))
- canvas = Canvas(root, width=ww, height=hh)
- canvas.pack()
- ppp = '0 64 128 192 255'.split()
- from tkFileDialog import askopenfilename
- img_data = askopenfilename(filetypes=[('png files', '.png')]) # needs to be placed after pack()
- image = Image.open(img_data)
- imw,imh = image.size
- img = Image.new('RGB', (imw,imh))
- rgb = image.convert("RGB")
- sss = list(rgb.getdata())
- ttt = set(sss)
- sss = str(sss)
- '''
- for t in ttt:
- rgb = '(%s, %s, %s)'%tuple([ppp[z/52] for z in t])
- sss = sss.replace(str(t),str(rgb))
- '''
- sss = eval(sss)
- img.putdata(sss)
- imgTk = ImageTk.PhotoImage(img)
- canvas.create_image(10, 10, anchor=NW, image=imgTk)
- root.update()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement